<分区>
此代码在 Google Chrome 中运行良好,但在 Internet Explorer 中无法运行:
document.getElementsByClassName('info')[i].remove();
有没有其他方法可以做同样的事情,或者我可以让 .remove()
在 Internet Explorer 中工作?
<分区>
此代码在 Google Chrome 中运行良好,但在 Internet Explorer 中无法运行:
document.getElementsByClassName('info')[i].remove();
有没有其他方法可以做同样的事情,或者我可以让 .remove()
在 Internet Explorer 中工作?
最佳答案
您必须获取父对象并调用 removeChild
var node = document.getElementsByClassName('info')[i];
node.parentNode.removeChild(node);
此外,由于您已经标记了 jQuery,因此您可以这样做
jQuery(".info").eq(i).remove()
因为 jQuery 会跨浏览器检查并使用正确的方法
关于javascript - .remove() 在 Internet Explorer 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32670780/
相关文章:
javascript - 单击 jQuery 从相同的 div 中选择一个
javascript - 通过不显眼的验证以 asp.net mvc 形式动态添加 bootstraph glyphicon
javascript - 如何将子框架中的location.href更改为相对路径?
javascript - 输入焦点不起作用/无法选择单选按钮 - Bootstrap
c# - 如何检测我的网站是在 Facebook iframe 中还是在独立网站中
javascript - 有人可以解释一下 reduce 方法在这个函数式 JavaScript 挑战中是如何工作的吗?