关于event.cancelBubble的描述

『本文地址:http://v1.djasp.net/Static/br/2058.stm

关于event.cancelBubble的描述
由于HTML中的对象都是层次结构,比如一个Table包含了多个TR,一个TR包含了多个TD.
★点击设计★ http://www.djasp.Net 全力打造WEB技术站点,欢迎大家访问!
Bubble就是一个事件可以从子节点向父节点传递,比如鼠标点击了一个TD,当前的event.srcElement就是这个TD,但是这种冒泡机制使你可以从TR或者Table处截获这个点击事件,但是如果你event.cancelBubble,则就不能上传事件。
本文由 点击设计 http://www.djasp.Net 收集整理。谢绝无聊之人转载!
举个简单的例子:
此内容来源于 ★点击设计★ http://www.djasp.Net 网页编程资讯官方网站!
比如你没有用CSS,但是想同意改变你的页面上的所有按钮的属性,你可以在页面load完毕后使用在body中使用onmouseover方法统一改变鼠标在按钮上和离开后的style,而不用对每个按钮都写一边。
请勿盗版 ★点击设计★ http://www.djasp.Net 网站上的内容,谢谢合作!
程序如下:
请勿盗版 ★点击设计★ http://www.djasp.Net 网站上的内容,谢谢合作!
<body onmouseover=mouse_over() onmouseout=mouse_out()>
更加精准的描述
a lot of events are passed upward through the DOM object structure, but you can use event.cancelBubble=true to stop this "bubbling". For example, if you click on the following button, the alert message boxes in both the button’s onclick event handler and the document’s onclick event handler will be displayed. But if you uncomment the cancelBubble line, you will only see the alert box in the button’s event handler get displayed:


<script language="javascript">
function document.onclick()
{
alert("in the document’s event handler!");
}

function clickMe()
{
alert("in the button’s event handler!");
//event.cancelBubble = true;
}
</script>

<input type="button" value="click me" onclick="clickMe()">
< span>

本文统计
上一篇: 防止网站内容被人小偷和采集的ASP…
下一篇: (没有了)
文章类别:常见问题经典收藏
最后更新:2007-2-28 14:49:23
浏览次数:
本栏最新文章
本栏推荐文章
随机酷站设计秀
网站导航 |走进点击 |点击作品 |服务项目 |联系我们 |设为首页 |加入收藏 |在线留言
点击设计
点击设计© Version: 2.3 WEB执行标准:W3C XHTML 1.1 / CSS 2.0 / Ajax
本站全面兼容 IE、FireFox、Netscape、Opera 等内核的浏览器
版权所有:点击设计 www.djasp.Net E-mail:djasp@qq.com
全程开发:秋水天子(Folier) QQ:39886616
版权所有:点击设计 www.djasp.net
浙ICP备05074939号