js中常见的一些兼容性问题,面试必备 |
您所在的位置:网站首页 › 常见的浏览器兼容性问题有哪些 › js中常见的一些兼容性问题,面试必备 |
javaScript中一些常见的兼容性问题整理 1) 滚动条: document.documentElement.scrollTop||document.body.scrollTop
2) 获取样式兼容 function getStyle(dom, styleName){ return dom.currentStyle? dom.currentStyle[styleName] getComputedStyle(dom)[styleName]; }
3) 网页可视区域兼容 window.innerHeight || document.documentElement.clientHeight window.innerWidth || document.documentElement.clientWidth
4) 事件对象兼容 evt = evt || window.event;
5) 阻止事件冒泡兼容 event.stopPropagation? event.stopPropagation():event.cancelBubble=true;
6)阻止默认行为兼容 evt.preventDefault?evt.preventDefault():evt.returnValue=false;
7)事件监听兼容 if(document.all){ dom.attactEvent(“onclick”, fn); } else { dom.addEventListener(“click”, fn); }
8)事件目标对象兼容 var t = event.target || event.srcElement; |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |