javascript获取style(兼容ie和w3c)

来源:互联网 发布:pymongo 查询数据 编辑:程序博客网 时间:2024/05/18 01:41

<script type="text/javascript">

window.onload=function(){

var oDiv=document.getElementById("oDiv")

//alert(oDiv.currentStyle.height)//400px 只适用于ie

/*var s=getComputedStyle(oDiv,null)

alert(s.height)//400px 适合w3c*/


alert(getRealStyle(oDiv,"backgroundColor"))

function getRealStyle(obj,s){

var style;
if(window.getComputedStyle){ //W3C
style=window.getComputedStyle(obj,null)
}else if(obj.currentStyle){//ie
style=obj.currentStyle
}
return style[s]

}

}
</script>

原创粉丝点击