<html>
<head>
<script>
alert(document.getElementById("a1").style.width);
</script>
</head>
<body>
<div id="a1" style="width:100px;">
</div>
</body>
</html>
网页错误详细信息用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; .NET4.0C)
时间戳: Mon, 29 Aug 2011 13:35:41 UTC
消息: 缺少对象
行: 4
字符: 1
代码: 0
URI: file:///C:/Users/denggg/Desktop/2.html
<head>
<script>
alert(document.getElementById("a1").style.width);
</script>
</head>
<body>
<div id="a1" style="width:100px;">
</div>
</body>
</html>
网页错误详细信息用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; .NET4.0C)
时间戳: Mon, 29 Aug 2011 13:35:41 UTC
消息: 缺少对象
行: 4
字符: 1
代码: 0
URI: file:///C:/Users/denggg/Desktop/2.html
<head>
</head>
<body>
<div id="a1" style="width:100px;">
</div>
<script>
alert(document.getElementById("a1").style.width);
</script>
</body>
</html>或者
html>
<head>
<script>
wundow.onload=function()
{
alert(document.getElementById("a1").style.width);
}
</script>
</head>
<body>
<div id="a1" style="width:100px;">
</div>
</body>
</html>
<head>
</head>
<body>
<div id="a1" style="width:100px;">
</div>
<script type="text/javascript">
alert(document.getElementById("a1").style.width);
</script>
</body></html>
当页面解析到js时 由于此时dom尚未加载成功 你却在js中对dom进行了操作