我在容器 (this.element
) 中有一个图像列表,我希望获取每个图像的 ID。
我有以下内容,但我被告知 value.attr 不是一个函数
。
我做错了什么?谢谢。
var images = this.element.find('img');
$.each(images, function(index, value){
console.log(value.attr(id));
});
我的 HTML 示例 -
<div id="front-page-gallery" class="image-gallery"> <!-- This is `this.element` above -->
<img id="image-7293" class="active" title="Home Page 1" src="http://www.example.com/wp-content/uploads/2014/02/Home-Page-1.jpg">
<img id="image-7294" title="Home Page 2" src="http://test.example.com/wp-content/uploads/2014/02/Home-Page-2.jpg">
<img id="image-7295" title="Home Page 3" src="http://test.example.com/wp-content/uploads/2014/02/Home-Page-3.jpg">
</div>
最佳答案
只需使用this.id
即可获取元素的id
var images = this.element.find('img');
$.each(images, function(){
console.log(this.id);
});
关于jquery - 获取容器中每个镜像的ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21608982/