简体   繁体   English

jquery 代码在 Firefox 和 Chrome 中有效,但在 IE11 中无效

[英]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.

相关问题 jQuery / Javascript函数适用于Chrome但不适用于IE11 - jQuery/Javascript function works in Chrome but not IE11 click()在Chrome中工作正常,但在IE11中工作不正常 - click() works fine in Chrome but not in IE11 chrome,firefox,ie11中的基本html代码功能,但不是ie9 - Basic html code functions in chrome, firefox, ie11, but NOT ie9 为什么这个代码不能在IE11,Chrome,Firefox中运行,但是可以在IE8中运行? - Why won't this code work in IE11, Chrome, Firefox, but will work in IE8? CSS微调器动画在Chrome上有效,但在IE11和FIrefox42上无效 - css spinner animation works at Chrome but not at IE11 and FIrefox42 在Kendo Scheduler议程视图上隐藏表格列-在Firefox / Chrome中有效,但不适用于IE11 - Hide table column on kendo scheduler agenda view - works in Firefox/Chrome but not IE11 jQuery适用于Chrome和firefox,但不适用于IE - jQuery works in Chrome and firefox, but not IE 表格不在DIV中(在IE 9中有效,但在Chrome或IE11中无效) - Form not staying within a DIV (Works in IE 9 but not Chrome or IE11) Chrome,firefox和IE11中的按钮间距不同 - Button spacing coming as different in Chrome, firefox and IE11 在IE11中缩放图像,但在Chrome / Firefox中显示正常 - Zoomed image in IE11 but displays fine in Chrome/Firefox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM