根據DOM的Javscript,DIV的寬度不算什麼。根據Javascript,DIV的寬度是什麼都沒有,爲什麼?
這是一個這麼簡單的小問題,但它很煩人。
<html>
<head>
<style>
div#foot_wrapper{
width:650px;
height:20px;
position:absolute;
bottom:10px;
background-color:#000000;
}
</style>
<script>
function align(div){
alert(div.style.width); // ---------------- box pops up blank?
div.style.left = (window.innerWidth/2) - (div.style.width/2);
}
</script>
</head>
<body onload="align(document.getElementById('foot_wrapper'))" onresize="align(document.getElementById('foot_wrapper'))" >
<div id="main">
</div>
<div id="foot_wrapper">
</div>
</body>
</html>
但是在較老的IE瀏覽器中不支持offsetWidth嗎? – user965369 2012-01-12 12:55:17
即使在IE 5.5中也支持(http://www.quirksmode.org/dom/w3c_cssom.html#t34)。它最初是微軟的一件事。 – kapa 2012-01-12 12:56:37
我得到一個無效的參數錯誤?它在Chrome中的作品:) – user965369 2012-01-12 13:01:43