此javascript代码不支持';我不能在Internet Explorer 11中工作 const images=document.querySelectorAll('.view content img') images.forEach(项目=>{ const src=item.getAttribute('data-original'); 康斯特新闻中心https://example.com“+src; item.setAttribute('src',newSrc); })
此代码将更改此javascript代码不支持';我不能在Internet Explorer 11中工作 const images=document.querySelectorAll('.view content img') images.forEach(项目=>{ const src=item.getAttribute('data-original'); 康斯特新闻中心https://example.com“+src; item.setAttribute('src',newSrc); }),javascript,html,Javascript,Html,此代码将更改 到 如你所见。 但是这段代码在InternetExplorer11中不起作用。 如何使此代码在Internet Explorer中工作?IE11中既不兼容箭头函数也不兼容forEach()方法。您需要像这样使用ES5重写上述内容: <script> const images = document.querySelectorAll('.view-content img') images.forEach(item => { const src = item.g
到
如你所见。
但是这段代码在InternetExplorer11中不起作用。
如何使此代码在Internet Explorer中工作?IE11中既不兼容箭头函数也不兼容forEach()方法。您需要像这样使用ES5重写上述内容:
<script>
const images = document.querySelectorAll('.view-content img')
images.forEach(item => {
const src = item.getAttribute('data-original');
const newSrc = 'https://example.com' + src;
item.setAttribute('src', newSrc);
})
</script>
const images=document.querySelectorAll('.view content img');
对于(var i=0;i
或者,如果您更喜欢使用ES6编写JavaScript,您可以使用类似于在生产环境中将JavaScript ES6编译为JavaScript ES5的工具链
<script>
const images = document.querySelectorAll('.view-content img');
for(var i = 0; i < images.length; i++) {
let src = images[i].getAttribute('data-original');
let newSrc = 'https://example.com' + src;
images[i].setAttribute('src', newSrc);
}
</script>