e.stopPropagation()兼容性处理

时间:2023-03-10 03:30:09
e.stopPropagation()兼容性处理

使用jquery库,e.stopPropagation()兼容所有。

原生的就要这么写

function stopPropagation(e){

e=window.event||e;

if(document.all){  //只有ie识别——————可能有误(document.all主要用来判断是否为ie浏览器)

e.cancelBubble=true;

}else{

e.stopPropagation();

}

}

//判断是否为IE

function isIE(){

  var userAgent = navigator.userAgent.toLowerCase();
  if(userAgent.indexOf("msie") >= 0 || userAgent.indexOf("trident") >= 0) return true;

}