javascript兼容性(实例讲解)
(编辑:jimmy 日期: 2025/11/6 浏览:3 次 )
1.事件冒泡:
//取消冒泡
if(e.stopPropagation){
e.stopPropagation();//w3c定义的APIbiaozhun
}else{
e.cancelBubble=true;//兼容IE 6,7,8浏览器
}
2.获取某个元素的CSS属性值:
//获取某个元素的CSS属性值
function getStyle(element,stylename){
if(element.currentStyle){
//IE
return element.currentStyle[stylename];
}else{
//其他浏览器
var computedStyle=window.getComputedStyle(element,null);
return computedStyle[stylename];
}
}
以上这篇javascript兼容性(实例讲解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
下一篇:清空元素html("") innerHTML="" 与 empty()的区别和应用(推荐)