<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
window.onload=function() {
var oDiv=document.getElementById('div1');
var oUl=oDiv.getElementsByTagName('ul')[0];
};
</script>
</head>
<body>
<div id="div1">
<ul id="ul1">
<li></li>
</ul>
</div>
</body>
</html>
chrome:oDiv.getElementById is not a function
注:如果将 var oUl=oDiv.getElementById('ul1');
改成var oUl=oDiv.getElementsByTagName('ul')[0];
就不会报错了,为什么会这样?
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
window.onload=function() {
var oDiv=document.getElementById('div1');
var oUl=oDiv.getElementsByTagName('ul')[0];
};
</script>
</head>
<body>
<div id="div1">
<ul id="ul1">
<li></li>
</ul>
</div>
</body>
</html>
chrome:oDiv.getElementById is not a function
注:如果将 var oUl=oDiv.getElementById('ul1');
改成var oUl=oDiv.getElementsByTagName('ul')[0];
就不会报错了,为什么会这样?