我被困在jquery遍历。
当我在console.log($('image'));我会得到如下
<div class="product-img-box" id="image">
<div id="wrap" style="top:0px;z-index:1;position:relative;"><a href="mydomain.com/media/catalog/product/c/e/ceramic_straightner_-_s3_red_black_1_1.jpg" class="cloud-zoom" id="zoom" rel="zoomWidth:'330', zoomHeight:'330', position:'right', adjustX:0, adjustY:0, lensOpacity:0.5, smoothMove:3, showTitle:'true', titleOpacity:0.5" style="position: relative; display: block;">
<img src="mydomain.com/media/catalog/product/cache/1/image/550x550/9df78eab33525d08d6e5fb8d27136e95/c/e/ceramic_straightner_-_s3_red_black_1_1.jpg" alt="Ceramic Straightner" style="width: 550px; display: block;" title="">
</a><div class="mousetrap" style="z-index: 999; position: absolute; width: 456px; height: 456px; left: 0px; top: 0px; cursor: move; background-image: url(mydomain.com/index.php/straighteners/);"></div></div>
</div>
我正试图遍历img tag.ow我可以访问。
答案 0 :(得分:1)
您需要img
元素选择器
$('img')
或
$('#image img')
console.log($('#image img'));
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="product-img-box" id="image">
<div id="wrap" style="top:0px;z-index:1;position:relative;"><a href="mydomain.com/media/catalog/product/c/e/ceramic_straightner_-_s3_red_black_1_1.jpg" class="cloud-zoom" id="zoom" rel="zoomWidth:'330', zoomHeight:'330', position:'right', adjustX:0, adjustY:0, lensOpacity:0.5, smoothMove:3, showTitle:'true', titleOpacity:0.5" style="position: relative; display: block;">
<img src="mydomain.com/media/catalog/product/cache/1/image/550x550/9df78eab33525d08d6e5fb8d27136e95/c/e/ceramic_straightner_-_s3_red_black_1_1.jpg" alt="Ceramic Straightner" style="width: 550px; display: block;" title="">
</a><div class="mousetrap" style="z-index: 999; position: absolute; width: 456px; height: 456px; left: 0px; top: 0px; cursor: move; background-image: url(mydomain.com/index.php/straighteners/);"></div></div>
</div>
&#13;
答案 1 :(得分:1)
您可以尝试:
$("#image").find("img");
答案 2 :(得分:0)
$("#image img");
或$("#image").find("img");
虽然通常第二个更快,但因为它被转换为原始的Javascript代码:document.getElementById("image").getElementsByTagName("img");
。