Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我的代码是这样布局的,
<div data-page-index="1" class="active"> <img src="foo.png" /> </div>
例如,如果我只有 div 类,如何将变量设置为图像路径
var image1 = $('.active').find(img);
所以我可以在必要时附加该图像?
src从图像的第一个实例中获取属性。
src
var image1 = $(".active").children("img").eq(0).attr("src");
工作示例