$('#newsImageGallery li').each(function() {
alert($(this));
});
在我的每个 li 中,我都有一个带有 id 的图像,我如何提醒该图像 id?
最佳答案
$('#newsImageGallery li').each(function() {
alert($(this).find("img").attr("id"));
});
或者当然,没有找到:
$('#newsImageGallery li img').each(function() {
alert($(this).attr("id"));
});
正如 Pointy 在下面提到的,如果您使用 jQuery 1.6+,最好使用 .prop 而不是 .attr:
$('#newsImageGallery li img').each(function() {
alert($(this).prop("id"));
});
关于javascript - 循环遍历列表并获取元素图像 id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10914213/