怎么设置div的onclick,只对该div有效,不影响div内元素

如题所述

这种情况  就是阻止事件起泡,也就是阻止事件向上传播,代码如下:

event.cancelBubble=true

IE下是cancelBubble=true,其他浏览器是stopPropagation()

温馨提示:内容为网友见解,仅供参考
第1个回答  2016-11-20

这是事件冒泡

var stopEvent = function(event){
    e = event || window.event;
    if(e.stopPropagation){
        e.stopPropagation();
    }else {
        e.cancelBubble = true; 
    } 
};

相似回答