惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
H
Help Net Security
The Cloudflare Blog
Y
Y Combinator Blog
A
Arctic Wolf
Cyberwarzone
Cyberwarzone
G
Google Developers Blog
Recent Announcements
Recent Announcements
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
博客园 - Franky
罗磊的独立博客
Martin Fowler
Martin Fowler
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 三生石上(FineUI控件)
N
News and Events Feed by Topic
F
Fortinet All Blogs
N
News | PayPal Newsroom
J
Java Code Geeks
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
博客园 - 聂微东
S
Securelist
C
CERT Recently Published Vulnerability Notes
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
S
Security Affairs
NISL@THU
NISL@THU
A
About on SuperTechFans
PCI Perspectives
PCI Perspectives
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Jina AI
Jina AI
Microsoft Azure Blog
Microsoft Azure Blog
AWS News Blog
AWS News Blog
GbyAI
GbyAI
C
Cyber Attacks, Cyber Crime and Cyber Security
V
Vulnerabilities – Threatpost
D
Docker
P
Proofpoint News Feed
W
WeLiveSecurity
Help Net Security
Help Net Security
The GitHub Blog
The GitHub Blog
The Last Watchdog
The Last Watchdog
The Hacker News
The Hacker News
博客园 - 叶小钗

博客园 - music000

分享:使用JQuery进行跨域请求 Flash Chart 谨防 url 传递参数未编码(转码)产生的陷阱 OSI七层网络模型与TCP/IP四层网络模型 一些数据库理论知识 Sqlserver中Compute By子句用法分析 数据查询的另类需求 A Preview of HTML 5 CSS Sprites 15 Rules for Faster-Loading Web Sites 关于"多级目录(分类)"的一些想法 ----- 实现方法 金额转换:阿拉伯数字转中文(SQL存储过程) 金额转换:阿拉伯数字转中文(javascript) 这两天不爽——公车上被误认为色狼、游泳撞破上嘴唇 如何获取字段中分隔符的个数?(sql语句) 关于GridView导出Excel的一些问题(采用Ajax出现的的问题及解决方法) - music000 - 博客园 固定表头 Reg-日期 安装 WebDesigner 之后,ASPNET 帐户没有对 IIS 的访问权。
Bubble in JavaScript DOM
music000 · 2007-05-20 · via 博客园 - music000

JavaScript的事件冒泡(转载)

<!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; charset=UTF-8" />
<meta name="developer" content="Realazy" />
<title>Bubble in JavaScript DOM</title>
<style type="text/css" media="screen">
 div * 
{display:block; margin:4px; padding:4px; border:1px solid white;}
 textarea 
{width: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 solid red';

    log.value 
= '鼠标现在进入的是: ' + this.nodeName;
   }
;
   all[i].onmouseout 
= function(e){
    
this.style.border = '1px solid white';
   }
;
  }


  
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 solid red';

    
if (e) //停止事件冒泡
     e.stopPropagation();
    
else
     window.event.cancelBubble 
= true;
    
    log.value 
= '鼠标现在进入的是: ' + this.nodeName;
   }
;
   all2[i].onmouseout 
= function(e){
    
this.style.border = '1px solid white';
   }
;
  }

 }

 window.onload 
= init;
    
//]]>
</script>
</head>
<body>
<h1>Bubble in JavaScript DOM</h1>
<p>DOM树的结构是:</p>
<pre><code>
UL
  - LI
     - A
   - SPAN
</code></pre>
<div>
 
<ul>
  
<li><href="#"><span>Bubbllllllllllllllle</span></a></li>
  
<li><href="#"><span>Bubbllllllllllllllle</span></a></li>
 
</ul>
</div>
<textarea></textarea>
<p>鼠标进入UL的任何一个子元素,如果不停止冒泡,我们从UL到SPAN都定义了鼠标悬停(<code>mouseover</code>)事件,这个事件会上升了UL,从而从鼠标所进入的元素到UL元素都会有红色的边。</p>
<div>
 
<ul>
  
<li><href="#"><span>Bubbllllllllllllllle</span></a></li>
  
<li><href="#"><span>Bubbllllllllllllllle</span></a></li>
 
</ul>
</div>
<p>如果停止冒泡,事件不会上升,我们就可以获取精确的鼠标进入元素。</p>
</body>
</html>

http://realazy.org/blog/2007/04/09/javascript-bubble-demo/