.remove()在Internet Explorer中不起作用 [英] .remove() not working in Internet Explorer

查看:128
本文介绍了.remove()在Internet Explorer中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码在Google Chrome浏览器中效果很好,但在Internet Explorer中不起作用:

This code works very well in Google Chrome, but wont work in Internet Explorer:

document.getElementsByClassName('info')[i].remove();

还有其他方法可以做同样的事情吗?还是可以使.remove()在Internet Explorer中工作?

Is there some other method to do the same thing or can I make .remove() work in Internet Explorer?

推荐答案

删除不受ie

您将必须获取父母并致电removeChild

You would have to get the parent and call removeChild

var node = document.getElementsByClassName('info')[i];
node.parentNode.removeChild(node);

此外,由于您已标记了jQuery,因此可以进行

Also since you have jQuery tagged you could just do

jQuery(".info").eq(i).remove()

jQuery会进行跨浏览器检查并使用正确的方法

as jQuery does cross browser checks and uses the correct methods

这篇关于.remove()在Internet Explorer中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆