[英]jquery code works in Firefox and Chrome but not in IE11
I encountered a slight problem.我遇到了一个小问题。 My jQuery code works as expected in Firefox and Chrome but not in IE11.我的 jQuery 代码在 Firefox 和 Chrome 中按预期工作,但在 IE11 中没有。 Not sure why it's not working.不知道为什么它不起作用。
Here is my HTML, CSS and jQuery:这是我的 HTML、CSS 和 jQuery:
let nodes = $('h2').contents().filter(function(i, node) { return node.nodeType === 3; }); Array.from(nodes).forEach(function(n) { return n.nodeValue = n.nodeValue.trim(); });
h2 img { width: 31px; height: 16px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <h2>This is a test <img class="test" src="https://www.iconsdb.com/icons/preview/red/new-xxl.png" alt="test" /></h2> <h2>This is another test <img class="test" src="https://www.iconsdb.com/icons/preview/red/new-xxl.png" alt="test" /></h2> <h2>foo bar <img class="test" src="https://www.iconsdb.com/icons/preview/red/new-xxl.png" alt="test" /></h2>
Would like it to work in IE11 as well.希望它也能在 IE11 中工作。 Any help is appreciated.任何帮助表示赞赏。
Array.from
is not supported in Internet Explorer. Internet Explorer 不支持Array.from
。
As you use jQuery, just call .each
on the nodes
collection:当您使用 jQuery 时,只需在nodes
集合上调用.each
:
nodes.each(function(_, n) {
n.nodeValue = String(n.nodeValue).trim();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.