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

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
A
About on SuperTechFans
博客园_首页
GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
NISL@THU
NISL@THU
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
博客园 - 司徒正美
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
Last Week in AI
Last Week in AI
S
SegmentFault 最新的问题
V
V2EX
D
DataBreaches.Net
B
Blog RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 聂微东
Vercel News
Vercel News
博客园 - 叶小钗
F
Full Disclosure
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享
博客园 - Franky
WordPress大学
WordPress大学
小众软件
小众软件
T
The Blog of Author Tim Ferriss
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
The Register - Security
The Register - Security
Y
Y Combinator Blog
Jina AI
Jina AI
月光博客
月光博客
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
量子位
云风的 BLOG
云风的 BLOG
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
Blog — PlanetScale
Blog — PlanetScale
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 三生石上(FineUI控件)
美团技术团队
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
Recent Announcements
Recent Announcements

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