我的代码直接贴上来:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
var list = document.getElementById("list");
var items = list.getElementsByTagName("li");
var len = items.length;
document.write(len);
</script>
</head>
<body>
<ul id="list">
<li> 123 </li>
<li>456</li>
<li>789</li>
</ul>
</body>
</html>
但是len的值打印不出来,不知为什么
------解决方案--------------------
<script type="text/javascript">
var list = document.getElementById("list");
var items = list.getElementsByTagName("li");
var len = items.length;
document.write(len);
</script>
这一段不要放head里,要放</ul>后面