日期:2014-05-16  浏览次数:20451 次

新手问题:写的树状代码为何不执行?
刚刚开始做web。仿照写了一个树状结构网页,点击图片或超连接可以显示隐藏的内容,就像csdn左边的树状,。
问题:1、点击图片或超连接,不能打开隐藏的内容,也不报错!
2、如何调试写的网页中的javascript代码?

------解决方案--------------------
<html>
<head>
<title> caidan </title>
<SCRIPT language=JavaScript>
var img1 = new Image();img1.src = "jia.gif ";
var img2 = new Image();img2.src = "jian.gif ";

function doOutline() {
var srcId, srcElement, targetElement,srcNum,toggleElement,toggleImage;
srcElement = window.event.srcElement;
if(srcElement.className.toUpperCase()== "LEVEL1 "){
var srcID=srcElement.id;
var m1 =srcID.substr( 0, 4);
var m2 =srcID.charAt(srcElement.id.length-1);
var targetElement=document.all(m1+ "s "+m2);
var srcElement=document.all(m1+ "i "+m2);
if(targetElement.style.display == "none "){
targetElement.style.display = "block ";
if (srcElement.className.toUpperCase() == "LEVEL1 ") srcElement.src = img2.src;
}else{
targetElement.style.display = "none ";
if (srcElement.className.toUpperCase() == "LEVEL1 ") srcElement.src = img1.src;
}
}
}
document.onclick = doOutline;
</SCRIPT>
</head>
<body>
<DL>
<DD> <img src= "jia.gif " class= "level1 " id=OUT0i1 onclick=doOutline> <A class= "level1 " id=OUT0a1 > 部门1 </A>
<DL style= "display:none " id=OUT0s1>
<DD> <img src= "jian.gif "> a
<DD> <img src= "jian.gif "> a
<DD> <img src= "jian.gif "> a
</DL>

<DD> <img src= "jia.gif " class= "level1 " id=OUT0i2> <A class= "level1 " id=OUT0a2 > 部门2 </A>
<DL style= "display:none " id=OUT0s2>
<DD> <img src= "jian.gif "> b
<DD> <img src= "jian.gif "> b
<DD> <img src= "jian.gif "> b
</DL>

<DD> <img src= "jia.gif " class= "level1 " id=OUT0i3 > <A class= "level1 " id=OUT0a3 > 部门3 </A>
<DL style= "display:none " id=OUT0s3>
<DD> <img src= "jian.gif "> c
<DD> <img src= "jian.gif "> c
<DD> <img src= "jian.gif "> c
</DL>
</DL>


</body>


</html>