js获取css属性值
2017-07-30 本文已影响14人
WangYatao
<body>
<p id=”qq” class=”ss” >sdf</p>
<script type=”text/javascript”>
function GetCurrentStyle (obj, prop) {
if (obj.currentStyle) {
return obj.currentStyle[prop];
}
else if (window.getComputedStyle) {
propprop = prop.replace (/([A-Z])/g, “-$1”);
propprop = prop.toLowerCase ();
return document.defaultView.getComputedStyle (obj,null)[prop];
}
return null;
}
var dd=document.getElementById(“qq”);
alert(GetCurrentStyle(dd,”width”));
</script>
</body>