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

推荐订阅源

大猫的无限游戏
大猫的无限游戏
H
Hacker News: Front Page
T
The Blog of Author Tim Ferriss
WordPress大学
WordPress大学
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Blog — PlanetScale
Blog — PlanetScale
Stack Overflow Blog
Stack Overflow Blog
F
Fortinet All Blogs
H
Help Net Security
罗磊的独立博客
D
DataBreaches.Net
MyScale Blog
MyScale Blog
美团技术团队
人人都是产品经理
人人都是产品经理
L
LangChain Blog
M
MIT News - Artificial intelligence
C
Check Point Blog
GbyAI
GbyAI
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
Y
Y Combinator Blog
雷峰网
雷峰网
Last Week in AI
Last Week in AI
F
Full Disclosure
量子位
V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
H
Hackread – Cybersecurity News, Data Breaches, AI and More
P
Proofpoint News Feed
爱范儿
爱范儿
A
About on SuperTechFans
MongoDB | Blog
MongoDB | Blog
腾讯CDC
博客园 - 【当耐特】
U
Unit 42
Martin Fowler
Martin Fowler
NISL@THU
NISL@THU
B
Blog
T
The Exploit Database - CXSecurity.com
Apple Machine Learning Research
Apple Machine Learning Research
L
Lohrmann on Cybersecurity
P
Proofpoint News Feed
有赞技术团队
有赞技术团队
C
CERT Recently Published Vulnerability Notes
The GitHub Blog
The GitHub Blog
T
Threatpost

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