为什么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+