DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> js事件冒泡實例分享(已測試)
js事件冒泡實例分享(已測試)
編輯:關於JavaScript     
網上的例子用的是$(".b").live("click",function(event){} ,jquery自動對live做了處理,阻止了事件冒泡。改成bind,實驗就能通過。
復制代碼 代碼如下:
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<script type="text/javascript" src="http://www.css88.com/tool/css3Preview/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function(){
$(".b").bind("click",function(event){
$(this).css("color","#FF3300");
event.stopPropagation()//注釋掉,<SPAN style="BACKGROUND-COLOR: rgb(255,255,255)">效果是不一樣的。</SPAN>
})
});
</script>
</head>
<body>
<div id="temp"></div>
<div class="b" style="background:#3ff333">wrapwrapwrapwrapwrapwrapwrap
<div style="background:#ffff11" class="b">這是公告標題1</div>
<div style="background:#ffff11" class="b">這是公告標題2</div>
<div style="background:#ffff11" class="b">這是公告標題3</div>
<div style="background:#ffff11" class="b">這是公告標題4</div>
wrapwrapwrapwrapwrapwrapwrap
</div>
</body>
</html>

以上代碼中添加與否
復制代碼 代碼如下:
event.stopPropagation();
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved