欢迎来到福编程网,本站提供各种互联网专业知识!

阻止JavaScript事件冒泡传递(cancelBubble 、stopPropagation)

发布时间:2007-05-08 作者: 来源:转载
cancelBubble在IE下有效stopPropagation在Firefox下有效复制代码代码如下:阻止JavaScript事件冒泡传递(cancelBubble、stopPropagation)functiondoSomething(obj,evt){alert(obj.id);vare=(evt)?evt:window.event;if(window.event){e.cancelBubble=true;}els
cancelBubble在IE下有效
stopPropagation在Firefox下有效
复制代码 代码如下:



阻止JavaScript事件冒泡传递(cancelBubble、stopPropagation)


functiondoSomething(obj,evt){
alert(obj.id);
vare=(evt)?evt:window.event;
if(window.event){
e.cancelBubble=true;
}else{
//e.preventDefault();
e.stopPropagation();
}
}




Thisisparent1div.



Thisischild1.



Thisisparent1div.





Thisisparent2div.



Thisischild2.Willbubble.



Thisisparent2div.





相关推荐