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+

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...