Step By Step 制作XML的Javascript树形目录(一)
很多地方都会用到树形目录,比如CSDN论坛的列表,这样的代码也有很多,但是很多人都是拿来主义,没有自己动手做个,下面我就和大家一起分享怎么来自己做一个XML做数据源的TreeMenu。从中你会看到很多有用的JS脚本和页面元素的一些重要但经常被我们忽略的属性用法。
Step1.倒着来,看看完成后的TreeMenu是什么样子的?

| JS脚本动态生成的HTML大纲,这个是动态生成的,页面源代码里没有 |
| <div id="MyDiv"> <span class="hasItems" id="csxmlTree" style="MARGIN-LEFT: 0px" text="根目录" expanding="true" target treeId> <img src="images/contract.gif">根目录</span><br> <span style="DISPLAY: none"><span class="hasItems" id="csxmlTree" style="MARGIN-LEFT: 16px" text="目录1" expanding="false" target treeId="1000"> <img src="images/contract.gif">目录1</span><br> <span class="Items" id="csxmlTree" style="MARGIN-LEFT: 32px" text="目录1.1" expanding="false" target treeId="2000" href="javascript:alert(this.innerHTML);"> <img src="images/endnode.gif">目录1.1</span><br> <span class="Items" id="csxmlTree" style="MARGIN-LEFT: 32px" text="目录1.2" expanding="false" target="_blank" treeId="2001" href="1.htm"> <img src="images/endnode.gif">目录1.2</span><br> <span class="hasItems" id="csxmlTree" style="MARGIN-LEFT: 16px" text="目录2" expanding="false" target treeId="3000"> <img src="images/contract.gif">目录2</span><br> <span class="Items" id="csxmlTree" style="MARGIN-LEFT: 32px" text="目录2.1" expanding="false" target treeId="3001"> <img src="images/endnode.gif">目录2.1</span><br> <span class="Items" id="csxmlTree" style="MARGIN-LEFT: 32px" text="目录2.2" expanding="false" target treeId="3002"> <img src="images/endnode.gif">目录2.2</span><br> <span class="Items" id="csxmlTree" style="MARGIN-LEFT: 32px" text="目录2.3" expanding="false" target treeId="3003"> <img src="images/endnode.gif">目录2.3</span><br> <span class="Items" id="csxmlTree" style="MARGIN-LEFT: 32px" text="目录2.3" expanding="false" target treeId="3004"> <img src="images/endnode.gif">目录2.3</span><br> <span class="hasItems" id="csxmlTree" style="MARGIN-LEFT: 16px" text="目录3" expanding="false" target treeId="4000"> <img src="images/contract.gif">目录3</span><br> <span class="Items" id="csxmlTree" style="MARGIN-LEFT: 32px" text="目录3.1" expanding="false" target treeId="4001"> <img src="images/endnode.gif">目录3.1</span><br> <span class="Items" id="csxmlTree" style="MARGIN-LEFT: 16px" text="目录4" expanding="false" target treeId="5000"> <img src="images/endnode.gif">目录4</span><br> </span> </div> |