javascript e.preventDefault 的 IE 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11524134/
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
IE Error with e.preventDefault
提问by Andy
I apologise in advance if this has already been covered but I'm new to this, I have seen there are other similar posts but none of them have helped so I am thinking there might be another issue.
如果这已经被涵盖,我提前道歉,但我是新手,我看到还有其他类似的帖子,但没有一个有帮助,所以我想可能还有另一个问题。
I have a modal popup and it works fine in Chrome but doesn't work in IE. The problem appears to be with the line
我有一个模态弹出窗口,它在 Chrome 中运行良好,但在 IE 中不起作用。问题似乎出在线路上
{ e.preventDefault(); }
It gives the following error.
它给出了以下错误。
Error: Object doesn't support property or method 'preventDefault'
错误:对象不支持属性或方法“preventDefault”
Like I said I am new to this and I've tried doing what it says in other logs by putting an if round it or just removing the line but with no luck so could anyone help me.
就像我说的那样,我对此很陌生,我已经尝试通过在其他日志中添加 if 或只是删除该行来执行它在其他日志中所说的操作,但没有运气,所以任何人都可以帮助我。
/* prevent default behaviour on click */
var e = this.browserEvent;
var tgt = this.triggeringElement;
/*e.preventDefault();*/
{ e.preventDefault(); }
/* Trigger JQuery UI dialog */
var horizontalPadding = 30;
var verticalPadding = 30;
$('<iframe id="modalDialog" src="' + $(tgt).attr("href") + '" />').dialog({
title: "IC v RT",
autoOpen: true,
width: 1050,
height: 700,
modal: true,
close: function(event, ui) {apex.event.trigger('#P28_AFTER_MODAL','select',''); $(this).remove();},
overlay: {
opacity: 0.5,
background: "black"}
}).width(1050 - horizontalPadding).height(700 - verticalPadding);
return false;
回答by Jashwant
event.preventDefault ? event.preventDefault() : event.returnValue = false;
回答by Roopali Rawat
if(event.preventDefault)
{
event.preventDefault();
}
else
{
event.returnValue = false;
}