div 叠加,点击时如何只激发顶层DIV的JS事件
展开全部
阻止冒泡,在你的function里加上stopevt(),就不会啦!
function getEvent() {
if (document.all) {
return window.event; //如果是ie
}
func = getEvent.caller;
while (func != null) {
var arg0 = func.arguments[0];
if (arg0) {
if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof(arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
return arg0;
}
}
func = func.caller;
}
return null;
}
function stopevt() {
var ev = getEvent();
if (ev.stopPropagation) {
ev.stopPropagation();
} else if (window.ev) {
window.ev.cancelBubble = true;
}
}
function getEvent() {
if (document.all) {
return window.event; //如果是ie
}
func = getEvent.caller;
while (func != null) {
var arg0 = func.arguments[0];
if (arg0) {
if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof(arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
return arg0;
}
}
func = func.caller;
}
return null;
}
function stopevt() {
var ev = getEvent();
if (ev.stopPropagation) {
ev.stopPropagation();
} else if (window.ev) {
window.ev.cancelBubble = true;
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询