JS实现阻止冒泡事件

来源:互联网 发布:ppt图表编辑数据没反应 编辑:程序博客网 时间:2024/05/23 14:13
function stopBubble(e){
//一般用在鼠标或键盘事件上
if(e && e.stopPropagation){
//W3C取消冒泡事件
e.stopPropagation();
}else{
//IE取消冒泡事件
window.event.cancelBubble = true;
}
};

然后在button的click 响应函数的末尾加上

var e = window.event || arguments.callee.caller.arguments[0];
stopBubble(e);
来阻止冒泡事件