Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 此关键字在$中不起作用。每个数组-IE11_Javascript_Jquery - Fatal编程技术网

Javascript 此关键字在$中不起作用。每个数组-IE11

Javascript 此关键字在$中不起作用。每个数组-IE11,javascript,jquery,Javascript,Jquery,我试图在jquery中使用$将图像的srcset值设置为src属性。这在chrome和Firefox中运行良好,它总是在IE中返回未定义的,因此会破坏我在IE11中的页面。下面是我的代码 $(document).ready(function(){ var img = $('img[srcset]'); $.each(img,function(){ this.src = this.srcset; }); }); 有人能帮忙解决这个问题吗。我有时会看到img的单位是美元。每个单位都

我试图在jquery中使用$将图像的srcset值设置为src属性。这在chrome和Firefox中运行良好,它总是在IE中返回未定义的,因此会破坏我在IE11中的页面。下面是我的代码

$(document).ready(function(){
  var img = $('img[srcset]');
  $.each(img,function(){
  this.src = this.srcset;
  });
});
有人能帮忙解决这个问题吗。我有时会看到img的
单位是美元。每个单位都没有定义。但当我在$之前检查时,每次执行,img都显示所有32个元素。困惑的请帮忙


提前感谢

使用
$(this.attr('src',$(this.attr('srcset'))
Try
this.src=this.getAttribute('srcset')我甚至尝试了$(this).srcset。通过检查img[i].srcset,尝试在纯javascript中使用for循环。这还返回未定义的.attr('img[srcset]')。attr('src',function(){return$(This.attr('srcset');})
Ok让我试试@TusharUse
$(this.attr('src',$(this.attr('srcset'))
Try
this.src=this.getAttribute('srcset')我甚至尝试了$(this).srcset。通过检查img[i].srcset,尝试在纯javascript中使用for循环。这还返回未定义的.attr('img[srcset]')。attr('src',function(){return$(This.attr('srcset');})好,让我试试@Tushar