兼容浏览器 阻止冒泡事件
3
2
1
<script>
var div = document.getElementsByTagName("div")
div[0].onclick=function(){
var ev = window.event||ev
alert(3)
}
div[1].onclick=function(){
var ev = window.event||ev
if( ev.cancelBubble=true){
ev.cancelBubble=true
}
else{
ev.stopPropagation()
}
alert(2)
}
div[2].onclick=function(){
var ev = window.event||ev
if( ev.cancelBubble=true){
ev.cancelBubble=true
}
else{
ev.stopPropagation()
}
alert(1)
}
</script>
注:ie 部分要分开写