首页 > Web开发 > 详细

常见的js兼容性问题

时间:2018-08-18 00:17:33      阅读:208      评论:0      收藏:0      [点我收藏+]

1.获取滚动条的距离

var sTop=document.documentElement.scrollTop  ||   document.body.scrollTop

2.获取非行间样式

IE:currentStyle[attr]

标准:getComputedStyle[attr]

function getStyle(obj,attr){

   if(obj.currentStyle){

      return  obj.currentStyle[attr];

  }else{

      return  getComputedStyle(obj,false)[attr];

  }

}

3.获取事件对象

var e = e || event;

4.获取键盘信息

e.keyCode  ||   e.which

5.阻止浏览器的默认行为

function prevent(e){

     if(e.preventDefault){

          e.preventDefault();

     }else{

          e.returnValue=false;

   }

}

6.阻止事件冒泡

e.stopPropagation ? e.stopPropagation() : e.cancelBubble=true;

7.事件监听

addEventListener()

attachEvent()

8.事件解绑

removeEventListener()

detachEvent()

9.获取事件源

e.target || e.srcElement;

 

       

常见的js兼容性问题

原文:https://www.cnblogs.com/jsjx-xtfh/p/9495849.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!