为什么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 });
解决方法
那是因为您使用的是所有浏览器都不支持的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+
原文地址:https://www.jb51.cc/jquery/150074.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。