Javascript 使用jQuery更改所有图像的图像源
我的页面上有一些空图像标签,其中一个图像存储在数据属性中 在页面加载时,我想从数据属性中获取此值,并将其放置在源中Javascript 使用jQuery更改所有图像的图像源,javascript,jquery,Javascript,Jquery,我的页面上有一些空图像标签,其中一个图像存储在数据属性中 在页面加载时,我想从数据属性中获取此值,并将其放置在源中 $('div').each('img').attr('src', $(this).data('src')); 这是正确的方法: $('div img').each(function(){ $(this).attr('src', $(this).data('src')); }); 演示:这是正确的方法: $('div img').each(function(){
$('div').each('img').attr('src', $(this).data('src'));
这是正确的方法:
$('div img').each(function(){
$(this).attr('src', $(this).data('src'));
});
演示:这是正确的方法:
$('div img').each(function(){
$(this).attr('src', $(this).data('src'));
});
演示:您没有正确使用。这里有一个使用示例
$('div img').each(function() {
var $this = $(this);
$this.attr('src', $this.data('src'));
})
你没有正确使用。这里有一个使用示例
$('div img').each(function() {
var $this = $(this);
$this.attr('src', $this.data('src'));
})
与使用
.each()
var images=document.querySelectorAll(“div img”),
imageCount=document.images.length;
对于(变量i=0;i
与使用
.each()
var images=document.querySelectorAll(“div img”),
imageCount=document.images.length;
对于(变量i=0;i