类型错误:e 未定义 - javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29149700/
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
TypeError: e is undefined - javascript
提问by Smiley
All other browsers work perfectly fine. However, when firefox tries to execute this code:
所有其他浏览器都可以正常工作。但是,当 Firefox 尝试执行此代码时:
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
it crashes and the console displays the following error: TypeError: e is undefined
它崩溃并且控制台显示以下错误:TypeError: e is undefined
edit 1:
编辑1:
function clickInactiveTab() {
$(this).attr({class: "activeTab"});
$(".inactiveTab").hide();
}
function clickX() {
$(this).parent().attr({class: "inactiveTab"});
$(".inactiveTab").show();
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
}
What it does it, change the style of a div when clicked and hides all other divs from the class. When someone clicks the x that's inside the div, it should change the style back and show the hidden divs.
它的作用是在单击时更改 div 的样式并隐藏类中的所有其他 div。当有人单击 div 内的 x 时,它应该将样式改回并显示隐藏的 div。
回答by epascarello
e is not defined so that would be the error
e 未定义,因此将是错误
function clickX(e) { //e needs to be in the arguments as long as the event is attached properly, this will work.
$(this).parent().attr({class: "inactiveTab"});
$(".inactiveTab").show();
e = e || window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
}
If you used jQuery to attach the event, there is no reason to be doing the check for event or stopPropagation.
如果您使用 jQuery 附加事件,则没有理由检查事件或 stopPropagation。