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

cancelBubble在IE下有效
stopPropagation在Firefox下有效
复制代码 代码如下:

 
 
 
 阻止JavaScript事件冒泡传递(cancelBubble 、stopPropagation) 
 
 
function doSomething (obj,evt) { 
 alert(obj.id); 
 var e=(evt)?evt:window.event; 
 if (window.event) { 
 e.cancelBubble=true; 
 } else { 
 //e.preventDefault(); 
 e.stopPropagation(); 
 } 

 
 
 
 
 

This is parent1 div.

 
  
 

This is child1.

 
 
 
 

This is parent1 div.

 
 
 
 
 

This is parent2 div.

 
  
 

This is child2. Will bubble.

 
 
 
 

This is parent2 div.

 
 
 
 

你可能感兴趣的:(阻止JavaScript事件冒泡传递(cancelBubble 、stopPropagation))