JavaScript   发布时间:2022-04-16  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript – jQuery this.remove() – vs. – $(‘#id’).Internet Explorer中的remove()(IE 9)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么this.remove()在IE9中不起作用?
<input type="button" value="Next1" id="nextButton1">
<br>
<input type="button" value="Next2" id="nextButton2">

$('#nextButton1').on('click',function() {
   this.remove(); // works in all browsers but IE9+
});

$('#nextButton2').on('click',function() {
   $('#nextButton2').remove(); //works in all browsers
});

JSFiddle live version

解决方法

是因您使用的是所有浏览器都不支持的ChildNode.remove()方法.
this ---> refers to a node. //WARNING: This is an experimental technology

但是jQuery的.remove()方法是跨浏览器的,因此要使用它,你必须将它包装在$(…)中,如下所示:

$(this).remove();

ChildNode.remove() Browser Compatibility

以下桌面浏览器支持this.remove():

- Chrome 23+
- Firefox 23+
- Opera 10+
- Safari 7+

大佬总结

以上是大佬教程为你收集整理的javascript – jQuery this.remove() – vs. – $(‘#id’).Internet Explorer中的remove()(IE 9)全部内容,希望文章能够帮你解决javascript – jQuery this.remove() – vs. – $(‘#id’).Internet Explorer中的remove()(IE 9)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。