html 消息 捕获与冒泡

<html>
<head>
<title>捕获 与 冒泡  实例</title>
</head>
<body>

<div id="div_test">
<p id="p_test">test test test test test test test test</p>
</div>

<input type="button" value="捕获" onclick="bh()">
<input type="button" value="冒泡" onclick="mp()">
<script language="javascript" type="text/javascript">

function bh(){

var div = document.getElementById("div_test");
var p = document.getElementById("p_test");

div.addEventListener("click",div_ok,true);

p.addEventListener("click",p_ok,true);

}

function mp(){

var div = document.getElementById("div_test");
var p = document.getElementById("p_test");

div.addEventListener("click",div_ok,false);

p.addEventListener("click",p_ok,false);

}

function div_ok(){
alert("div capture");
}

function p_ok(){
alert("p capture");
}

</script>
</body>
</html>

捕获 div_capture  p_capture

冒泡 p_capture div_capture

posted @ 2012-03-27 22:49  十二十二  阅读(219)  评论(0编辑  收藏  举报