兼容主流浏览器的阻止冒泡的方法:

1
2
3
4
5
6
7
8
function stopPropagation(e) {  
e = e || window.event;
if(e.stopPropagation) { //W3C阻止冒泡方法
e.stopPropagation();
} else {
e.cancelBubble = true; //IE阻止冒泡方法
}
}

调用:

1
2
3
4
document.getElementById('btn_show').onclick = function(e) {  
document.getElementById('need_hide').style.display = 'block';
stopPropagation(e);
}