1. 程式人生 > >js控制點選事件冒泡,相容ie火狐蘋果

js控制點選事件冒泡,相容ie火狐蘋果



 function getEvent(){
      if(window.event)    {return window.event;}
      func=getEvent.caller;
      while(func!=null){
          var arg0=func.arguments[0];
          if(arg0){
              if((arg0.constructor==Event || arg0.constructor ==MouseEvent
                 || arg0.constructor==KeyboardEvent)
                 ||(typeof(arg0)=="object" && arg0.preventDefault
                 && arg0.stopPropagation)){
                  return arg0;
              }
          }
          func=func.caller;
      }
      return null;
 }
  //阻止事件冒泡
    function stopEventBubble(event){
        var e=event || window.event;

        if (e && e.stopPropagation){
            e.stopPropagation();   
        }
        else{
            e.cancelBubble=true;
        }
    }