取大图 js

  1. 最简单的取
    var imgs = $("#imgC").find("img");
    for (var i in imgs) {console.log($(imgs[i]).attr('src'));};
  2. 替换图片大小
    var imgs = $("#imgC").find("img");
    for (var i in imgs) {console.log($(imgs[i]).attr('src').replace("$_14.JPG", "$_10.JPG"));};
  3. 加入 img 标记, 并合并输出
  • var imgs = $("#imgC").find("img");
    var htmlStr = "";
    for (var i = 0; i < imgs.length; i++) {
    try {
    if ($(imgs[i]) && $(imgs[i]).attr('src')) {
    htmlStr += "<img src='" + $(imgs[i]).attr('src').replace("$_14.JPG", "$_10.JPG") + "'>\r\n";
    }
    } catch (err) {
    console.log("error: " + err);
    }

    };
    console.log(htmlStr);

  1. 加入全部需要 html 元素
  • var imgs = $("#imgC").find("img");
    var htmlStr = "

    ";
    for (var i = 0; i < imgs.length; i++) {
    try {
    if ($(imgs[i]) && $(imgs[i]).attr('src')) {
    if (0 === i % 2) {
    htmlStr += "

    <img src='" + $(imgs[i]).attr('src').replace("$_14.JPG", "$_12.JPG") + "'>\r\n";
    } else {
    htmlStr += "<img src='" + $(imgs[i]).attr('src').replace("$_14.JPG", "$_12.JPG") + "'>

    \r\n";
    }

          }
      } catch (err) {
          console.log("error: " + err);
      }
      
    

    };
    htmlStr += "

    ";
    console.log(htmlStr);

标签: none

添加新评论