div 叠加,点击时如何只激发顶层DIV的JS事件

2025-03-26 05:51:16
推荐回答(2个)
回答1:

阻止冒泡,在你的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;
}
}

回答2:

z-index

z轴位置