한국어
<!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" lang="zh" xml:lang="zh"> <head> <meta http-equiv="Content-Type" content="text/html; -8" /> <meta name="developer" content="Realazy" /> <title>JavaScript DOM의 버블</title> <style type="text/css" media="screen"> div * {display: 차단하다; 여백:4px; 패딩:4px; 테두리:1px 단색 흰색;} textarea {너비:20em; height:2em;} </style> <script type="text/javascript"> //<![CDATA[ function init(){ var log = document.getElementsByTagName('textarea')[0]; var all = document.getElementsByTagName('div')[0].getElementsByTagName('*'); for (var i = 0, n = all.length; i < n; ++i){ all[i].onmouseover = function(e){ this.style.border = '1px 단색 빨간색'; log.value = '鼠标现에서 현재 상태: ' + this.nodeName; }; all[i].onmouseout = function(e){ this.style.border = '1px 단색 흰색'; }; } var all2 = document.getElementsByTagName('div')[1].getElementsByTagName('*'); for (var i = 0, n = all2.length; i < n; ++i){ all2[i].onmouseover = function(e){ this.style.border = '1px 단색 빨간색'; if (e) //停止事件冒泡 e.stopPropagation(); 그렇지 않으면 window.event.cancelBubble = true; log.value = '鼠标现에서 현재 상태: ' + this.nodeName; }; all2[i].onmouseout = function(e){ this.style.border = '1px 단색 흰색'; }; } } window.onload = 초기화; //]]> </script> </head> <body> <h1>JavaScript DOM의 버블</h1> <p>DOM树的结构是:</p> <pre><code> UL - LI - A - SPAN </code></pre> <div> <ul> <li><a href="#"><span>Bubbllllllllllllllle</span></a></li> <li><a href ="#"><span>Bubbllllllllllllllle</span></a></li> </ul> </div> <textarea></textarea> <p>鼠标进入UL的任何一个子元素,如果不停止冒泡,我们从UL到SPANت义了鼠标悬停(<code>mouseover</code>)事件,这个事件会上升了UL,从而从鼠标所了鼠标悬停(<code>mouseover</code>)素city는 컬러풀한 색을 가지고 있습니다. </p> <div> <ul> <li><a href="#"><span>Bubbllllllllllllll</span></a></li> <li><a href="#"><span >Bubbllllllllllllllle</span></a></li> </ul> </div> <p>如果停止冒泡,事件不会上升,我们就可以获取精确的鼠标进入元素。</p> < /본문> </html>