javascrip阻止事件冒泡的通用函数:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<div id="d">kkkkkkkkkk</div>
<li>aa</li>
<div>
<li>aa</li>
</div>
<script>
//阻止事件冒泡的通用函数
function stopBubble(e){
if(e&&e.stopPropagation){
e.stopPropagation();
}else{
window.event.cancelBubble=true;
}
}
//定位遍历所有DOM元素
var all=document.getElementsByTagName("*");
for(var i=0;i<all.length;i++){
all[i].onmouseover=function(e){
this.style.border="1px solid red";
stopBubble(e);
};
all[i].onmouseout=function(e){
this.style.border="0px";
stopBubble(e);
};
}
</script>
</body>
</html>