我正在遍历元素并获取该元素src
的子元素的属性。我有这个 HTML 代码:
<noscript data-alt="super awesome">
<img src="http://farm9.staticflickr.com/8235/8585847956_39864361e3.jpg" alt="something" />
</noscript>
<noscript data-alt="super awesome">
<img src="http://farm9.staticflickr.com/8235/8585847956_39864361e3.jpg" alt="something" />
</noscript>
和 jQuery:
$('body').children().each(function() {
var noscriptTag = $(this)[0];
var imgAlt = noscriptTag.getAttribute("data-alt");
var img_src = noscriptTag.find('img');
var img_regular = img_src.getAttribute("src");
console.log(img_regular);
});
但我收到了这个错误:
Uncaught TypeError: Object #<HTMLElement> has no method 'find'
我还尝试了各种其他组合(如$(this).find('img');
),但没有成功。
这是演示:http: //jsfiddle.net/LjWhw/
如何定位该img
元素的标签?谢谢!
更新:您不能<noscript>
使用 JavaScript 定位内部元素。