js中常见的浏览器兼容问题

总结一些常见的浏览器中的兼容问题

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、事件对象兼容

e  = e || window.event;

5、阻止事件冒泡兼容

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

6、事件目标对象兼容

var src = event.target || event.srcElement;

7、阻止默认行为兼容

evt.preventDefault?evt.preventDefault():evt.returnValue=false;

 

你可能感兴趣的:(Web前端基础)