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

推荐订阅源

美团技术团队
Attack and Defense Labs
Attack and Defense Labs
Google Online Security Blog
Google Online Security Blog
SecWiki News
SecWiki News
N
News and Events Feed by Topic
O
OpenAI News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
AI
AI
L
LINUX DO - 最新话题
S
Securelist
Cisco Talos Blog
Cisco Talos Blog
V
Vulnerabilities – Threatpost
Webroot Blog
Webroot Blog
T
Threatpost
A
Arctic Wolf
罗磊的独立博客
T
Tor Project blog
The Hacker News
The Hacker News
C
Cybersecurity and Infrastructure Security Agency CISA
N
News | PayPal Newsroom
Latest news
Latest news
Y
Y Combinator Blog
S
Schneier on Security
T
Troy Hunt's Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security @ Cisco Blogs
量子位
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
L
Lohrmann on Cybersecurity
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Help Net Security
Help Net Security
腾讯CDC
The Last Watchdog
The Last Watchdog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed
Cloudbric
Cloudbric
Simon Willison's Weblog
Simon Willison's Weblog
AWS News Blog
AWS News Blog
NISL@THU
NISL@THU
GbyAI
GbyAI
B
Blog
Spread Privacy
Spread Privacy
宝玉的分享
宝玉的分享
S
Secure Thoughts
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
D
Docker
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 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/