欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js 獲取計算后的樣式寫法及注意事項

 更新時間:2013年02月25日 16:52:57   作者:  
復合樣式:currentStyle;注意在獲取復合樣式時要單獨寫,不能寫background,接下來將詳細介紹下實現(xiàn)方法,感興趣的你可不要錯過了哈
currentStyle
1.復合樣式:currentStyle取不到
例:background、margin
2.取默認樣式
3.只能讀
復制代碼 代碼如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>獲取計算后的樣式</title>
<style type="text/css">
#div1{ height:100px; background:#069;}
</style>
<script type="text/javascript">
//兼容
function getStyle(obj, name)
{
if(obj.currentStyle)
{
return obj.currentStyle[name];
}
else
{
return getComputedStyle(obj, false)[name];
}
}
window.onload=function()
{
var oDiv=document.getElementById('div1');
alert(getStyle(oDiv, 'width'));
alert(getStyle(oDiv, 'backgroundColor')); //注意在獲取復合樣式時要單獨寫,不能寫background
};
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>

相關(guān)文章

最新評論