javascript兼容性(实例讲解)

 更新时间:2017年08月15日 07:58:31   投稿:jingxian  
下面小编就为大家带来一篇javascript兼容性(实例讲解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

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兼容性(实例讲解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

最新评论