style.height 獲取的是行間的樣式
currentStyle.height、getComputedStyle(elem,null).height?獲取的是 div 的 content 的寬高,
clientHeight 獲取的是 content+padding,
offsetHeight 獲取的是content+padding+border。
<script> window.onload = function(){var div1 = document.getElementById('div1');var prop = '';if(div1.currentStyle){// IE瀏覽器下獲取行間或樣式表樣式prop = div1.currentStyle.height;}else if(window.getComputedStyle){// 標準瀏覽器下獲取計算樣式,兩種寫法都可以// prop = document.defaultView.getComputedStyle(div1,null).height;prop = window.getComputedStyle(div1,null).height;} console.log(prop);// height:auto; ==》 IE返回的是auto,標準瀏覽器返回的是實際值 } </script>
?