兼容

1.获取非行内样式的兼容性函数
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}
return getComputedStyle(obj.nul()[attr];
}

2.阻止事件冒泡的兼容
if(evt.stopPropagation){
evt.stopPropagation();
else{
evt.cancelBubble = true;
}

3.阻止事件默认行为的兼容
if(evt.preventDefault){
evt.preventDefault();
}else{
evt.returnValue = false;
}

4.事件处理兼容、
function addEvent(obj,type,fn){
if(obj.addEventListenter){
obj.addEventListenter(type,fn);
}else{
obj.attachEvent("on"+type,fn);
}
}

猜你喜欢

转载自blog.51cto.com/13570197/2330918