Mel*_*Dog 8 javascript each jquery jquery-selectors
我有一系列的图像,每个图像都有"照片"类;
我想浏览其中的每一个并检索照片源,以便稍后在if语句中使用.我写了下面的代码来做到这一点,但没有成功:
$.each($(".photo"), function() {
var imgsrc = $(this).attr("src").length;
console.log(imgsrc);
});
Run Code Online (Sandbox Code Playgroud)
我不知道我在哪里出错了.这似乎对我有意义,但我在控制台中没有得到任何东西.
谁能指出我正确的方向?
Ent*_*rJQ 19
如果您为所有img标签指定了相同的类名,那么试试这个,
$(".photo").each(function() {
imgsrc = this.src;
console.log(imgsrc);
});
Run Code Online (Sandbox Code Playgroud)