1. 程式人生 > >javascript兼容性

javascript兼容性

元素 javascrip var ets ati can compute asc 其他

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兼容性