javascript Internet Explorer 是否支持 e.preventDefault

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4479216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 13:49:41  来源:igfitidea点击:

does internet explorer supports e.preventDefault

javascriptinternet-explorer

提问by sushil bharwani

Does internet explorer does not support e.preventDefaultin javascript? If not what is the reason and what are the alternatives? Please do not suggest any solutions with libraries like jQuery, mootools, etc.

e.preventDefaultjavascript中不支持 Internet Explorer吗?如果不是,原因是什么,有什么替代方法?请不要建议使用 jQuery、mootools 等库的任何解决方案。

if (!e) e = window.event;

if (e.preventDefault) { 
    e.preventDefault(); 
} else {
    e.returnValue = false;
}

回答by Felix Kling

Ok if you insist:

好的,如果你坚持:

event.preventDefaultdoes not work, because it does not exist in IE.

event.preventDefault不起作用,因为它在 IE 中不存在。

For the reason why it does not exist, one would have to work for MS. But in general, IE is not always conform to the standards.

由于它不存在的原因,必须为 MS 工作。但总的来说,IE并不总是符合标准。

The documentationsays you can set event.returnValue:

文件说,你可以设置event.returnValue

false
Default action of the event on the source object is canceled.

false
事件对源对象的默认操作被取消。

and further:

并进一步:

Remarks

The value of this property takes precedence over values returned by the function, such as through a Microsoft JScript return statement.

Standards Information

There is no public standard that applies to this property.

评论

此属性的值优先于函数返回的值,例如通过 Microsoft JScript 返回语句返回的值。

标准信息

没有适用于该物业的公共标准。

preventDefaultseems to be supported in IE9.

preventDefault似乎在 IE9 中受支持。

回答by Shadow Wizard is Ear For You

It does not support it because someone in Microsoft decided so.

它不支持它,因为 Microsoft 的某个人决定这样做。

Alternative is the event.cancelBubble.

另一种选择是event.cancelBubble