有一个简单的HTML和JavaScript代码:element.style显示不正确的信息
<html>
<head>
<style>p { height: 100px;} </style>
<script>
window.onload = function(){
var p = document.getElementsByTagName("p")[0];
alert("actual height is " + p.style.height);
};
</script>
<title>JavaScript Tests</title>
</head>
<body>
<p>
100px height p element
</p>
</body>
</html>
但是,当我们运行它的实际高度等于空字符串。
你能解释一下为什么?
谢谢。
请注意,getComputedStyle()在所有流行的IE版本中都得不到很好的支持。 – cdhowie 2010-12-08 06:49:21