ʼþðÅÝ£ºÊ²Ã´ÊÇʼþðÅÝ£¬Í¨Ë×µÄÀ´½²¾ÍÊÇÎÒÃÇΪҳÃæÄÚbodyÌí¼ÓÒ»¸öµ¥»÷ʼþ£¬Í¬ÑùÔÙΪҳÃæÄÚliÔªËØÌí¼ÓÒ»¸öµ¥»÷ʼþ¡£µ±Äãµ¥»÷liµÄʱºò£¬bodyµÄʼþÒ²»á±»´¥·¢£¬ÒòΪli±»°üº¬ÔÚbodyÔªËØÄÚ£¬ËùÒÔÄãµ¥»÷ÁËliͬʱҲµ¥»÷ÁËbody¡£Õâ¾ÍÊÇʼþðÅÝ£¡
ÔÚÓÐЩʱºò£¬ÎÒÃÇÒª×èÖ¹ÕâÖÖÇé¿ö·¢Éú£¬Ò²¾ÍÊǵ¥»÷liʼþ£¬²»»á´¥·¢bodyµÄʼþ¡£ Õâ¾Í½Ð×èֹðÅÝ!
ÏÂÃæÊÇÒ»¸öСDEMO£º
<!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> <style> body { color:#333; font-size:12px; } </style> </head> <body> <p>ʲôÊÇʼþðÅÝ,ͨË×µÄÀ´½²¾ÍÊÇ ÎÒÃÇΪҳÃæÄÚbodyÌí¼ÓÒ»¸öµ¥»÷ʼþ,ͬÑùÔÙΪҳÃæÄÚliÔªËØÌí¼ÓÒ»¸öµ¥»÷ʼþ..µ±Äãµ¥»÷liµÄʱºò.<br> bodyµÄʼþÒ²»á±»´¥·¢.....ÒòΪli±»°üº¬ÔÚbodyÔªËØÄÚ...Äãµ¥»÷ÁËliͬʱҲµ¥»÷ÁËbody...Õâ¾ÍÊÇʼþðÅÝ....<br /> ÔÚÓÐЩʱºò.ÎÒÃÇÒª×èÖ¹ÕâÖÖÇé¿ö·¢Éú...Ò²¾ÍÊǵ¥»÷liʼþ.²»»á´¥·¢bodyµÄʼþ.... Õâ¾Í½Ð×èֹðÅÝ! <div id="a"> <ul id="lia"> Çëµ¥»÷ÏÂÃæµÄÁбí.»á´¥·¢bodyʼþ <li>ÏîÄ¿1</li> <li>ÏîÄ¿2</li> <li>ÏîÄ¿3</li> </ul> <ul id="lib"> Çëµ¥ÏÂÃæµÄÁбí.²»»á´¥·¢bodyʼþ. <li>ÏîÄ¿1</li> <li>ÏîÄ¿2</li> <li>ÏîÄ¿3</li> </ul> </div> <script language="javascript"> document.body.onclick = function(){//Ê×ÏÈΪbodyÔªËØ°ó¶¨Ò»¸öµ¥»÷ʼþ alert("BODYʼþ");//µ¥»÷Ò³Ãæ¼´µ¯³ö¶Ô»°¿ò } function att_Event(){//ΪµÚÒ»×éliÔªËØ°ó¶¨onclickʼþ var li = document.getElementById("lia").getElementsByTagName("li"); for(var i=0;i<li.length;i++){ li[i].onclick = function(){ alert("Liʼþ"); } } } function att_Event_b(){//ΪµÚ¶þ×éliÔªËØ°ó¶¨onclickʼþ var li = document.getElementById("lib").getElementsByTagName("li"); for(var i=0;i<li.length;i++){ li[i].onclick = function(e){ alert("Liʼþ"); stopBubble(e); //ÔËÐÐ×èֹðÅݵĺ¯Êý } } } //¸Ãº¯ÊýµÄ¹¦ÄÜÓÃÀ´×èֹʼþðÅÝ£®²¢¼æÈݶàä¯ÀÀÆ÷ function stopBubble(e){ //Èç¹û´«ÈëÁËʼþ¶ÔÏó.ÄÇô¾ÍÊÇ·ÇIEä¯ÀÀÆ÷ if(e){ //Òò´ËËüÖ§³ÖW3CµÄstopPropation()·½·¨ e.stopPropagation(); } else{ //·ñÔò,ÎÒÃǵÃʹÓÃIEµÄ·½Ê½À´È¡ÏûʼþðÅÝ window.event.cancelBubble = true; } } window.onload = function(){ att_Event(); att_Event_b(); } </script> </body> </html>
ÍƼöÐÅÏ¢
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- jQuery Tooltips²å¼þ
- jQueryµÄ.bind()¡¢.live()ºÍ.delegate(....
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- Ä㲻ϲ»¶»ðºü£¬µ«ÓÖϲ»¶firebug£¬ÄǾ͸úÎÒÒ»ÆðÀ´ÔÚIEÉÏ....
- ¸ù¾ÝÏÔʾÆ÷·Ö±æÂʵ÷ÕûÒ³ÃæÏÔʾµÄJavascript½Å±¾
- jQuery дµÄ·ÂÐÂÀË΢²© ÏòϹö¶¯Ð§¹û¡¾×ªÔØ¡¿
- ͨÓõÄJqueryÑ¡ÔñÆ÷
- jQuery ½áºÏ Json Ìá½»Êý¾Ýµ½Webservice£¬....
- ×ÔÖÆjQueryÖÇÄÜÌáʾ²å¼þһö
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- js»ñÈ¡srcÖд«µÝµÄ²ÎÊý
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- ÈÃä¯ÀÀÆ÷ÆÁ±ÎµôJavaScriptµÄ³ö´íÌáʾ
- github²»ÄܼÓÔØcss¡¢js½â¾ö°ì·¨
- ÎÒÖªµÀµÄJavaScript -- Éè¼Æģʽ(ÇŽÓ)Ó¦ÓÃÖ® ¨C ....
- 15¸öÖµµÃ¿ª·¢ÈËÔ±¹Ø×¢µÄjQuery¿ª·¢¼¼ÇɺÍÐĵÃ
- dz̸JavascriptÃæÏò¶ÔÏó±à³Ì
- JS¼òµ¥¶¯»·â×°
- JavaScript³õѧÕßӦעÒâµÄÆ߸öϸ½Ú
- jQuery Tooltips²å¼þ
ÆÀÂÛ