TypeError: e is undefined - javascript
TypeError: e is undefined - javascript
所有其他浏览器都可以正常工作。但是,当 firefox 尝试执行此代码时:
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
它崩溃并且控制台显示以下错误:
类型错误:e 未定义
编辑 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();
}
它的作用是,单击时更改 div 的样式并从 class 中隐藏所有其他 div。当有人单击 div 内的 x 时,它应该将样式改回并显示隐藏的 divs。
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();
}
如果您使用 jQuery 附加事件,则没有理由检查事件或停止传播。
所有其他浏览器都可以正常工作。但是,当 firefox 尝试执行此代码时:
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
它崩溃并且控制台显示以下错误: 类型错误:e 未定义
编辑 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();
}
它的作用是,单击时更改 div 的样式并从 class 中隐藏所有其他 div。当有人单击 div 内的 x 时,它应该将样式改回并显示隐藏的 divs。
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();
}
如果您使用 jQuery 附加事件,则没有理由检查事件或停止传播。