阻止事件冒泡
<div style="height:30px;line-height:30px;background:#FF0;text-align:center;" id="zz"><a href="http://www.baidu.com">阻止事件冒泡</a></div>
<script type="text/javascript">
var $ = function(id){
return document.getElementById(id);
}
$('zz').onclick = function(e){
$('zz').innerHTML += ",事件已经点击了!";
var e = e||window.event;
if (e.stopPropagation)
{
e.stopPropagation(); // 阻止冒泡
e.preventDefault(); // 阻止默认事件
}
else
{
e.cancelBubble =true; // 阻止冒泡
e.returnValue = false; // 阻止默认事件
}
}
document.documentElement.onclick = function(e){
$('zz').innerHTML += ",冒泡没阻止成功!";
}
</script>