我試過這個只在IE9中,我只收到一個空字符串 - 沒有邊框寬度。哪裏不對?!爲什麼不返回DOM元素邊框寬度?
<!DOCTYPE html><html><head>
<style type="text/css">
.myCanvas {
border-width: 2px;
border-style: solid;
border-color: red;
}
</style>
</head><body>
<div class="myCanvas">Something here</div>
<script type="text/javascript">
(function(){
var borderWidth = document.getElementsByTagName('div')[0].style.borderWidth;
console.log(borderWidth);
})();
</script>
</body>html>
你正在看的是style屬性設置的style屬性,你需要看的是計算的樣式。 – Musa