<script>
function bb(obj,evt)
{
alert('kk');
var e=(evt)?evt:window.event; //判断浏览器的类型,在基于ie内核的浏览器中的使用cancelBubble
if (window.event) {
e.cancelBubble=true;
} else {
//e.preventDefault(); //在基于firefox内核的浏览器中支持做法stopPropagation
e.stopPropagation();
}
}
</script>
<table onclick="alert('table');">
<tr><td onclick="bb(this,event);">00000</td></tr>
</table>
function bb(obj,evt)
{
alert('kk');
var e=(evt)?evt:window.event; //判断浏览器的类型,在基于ie内核的浏览器中的使用cancelBubble
if (window.event) {
e.cancelBubble=true;
} else {
//e.preventDefault(); //在基于firefox内核的浏览器中支持做法stopPropagation
e.stopPropagation();
}
}
</script>
<table onclick="alert('table');">
<tr><td onclick="bb(this,event);">00000</td></tr>
</table>
本文通过一个具体的HTML和JavaScript实例介绍了如何阻止事件冒泡。在表格单元格点击事件中,通过判断浏览器类型并使用特定的方法(如cancelBubble或stopPropagation),可以有效地阻止事件向上级元素传播。
1957

被折叠的 条评论
为什么被折叠?



