做的遍历树,有问题
<!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=gb2312" />
<title>无标题文档</title>
</head>
<body >
<script type="text/javascript">
function showlist(list){
var k=list.childNodes.length;
if(k==0){return;}
else{
for(i=0;i<k;i++){
alert(list.childNodes[i].tagName);
showlist(list.childNodes[i]);}
}
}</script>
<div onclick=showlist(this)><ul><li><a href="" title=""><span></span></a></li><li></li></ul>
<p><span></span></p>
<div><p></p></div></div>
</body>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body >
<script type="text/javascript">
function showlist(list){
var k=list.childNodes.length;
if(k==0){return;}
else{
for(i=0;i<k;i++){
alert(list.childNodes[i].tagName);
showlist(list.childNodes[i]);}
}
}</script>
<div onclick=showlist(this)><ul><li><a href="" title=""><span></span></a></li><li></li></ul>
<p><span></span></p>
<div><p></p></div></div>
</body>
</html>
(只能遍历出<ul><li><a href="" title=""><span></span></a></li><li></li></ul>这些标签。
哪位高手能帮忙改进,谢谢!

浙公网安备 33010602011771号