• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

XML+ JS创建树形菜单_xml

xml 搞代码 7年前 (2018-06-15) 168次浏览 已收录 0个评论

简单说明:

思路:
从数据岛menuxml中读取数据,从树的根节点开始分析树, 利用 hasChildNodes() [方法:是否含有子节点 ] 判断当前节点是否有子节点,如果有子节点继续向下分析 childNodes [对象:子节点对象集合] ,否则返回当前分析结果(树结点对象)。

主要的函数:

http://www.gaodaima.com/33492.htmlXML+ js创建树形菜单_xml

createTree(thisn /*树结点*/ , sd/*树深度*/)

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<HTML>
<HEAD>
<TITLE> DSTree </TITLE>
<META NAME=”Author” CONTENT=”[email protected]” >
<style>
body,td{font:12px verdana}
#treeBox{background-color:#fffffa;}
#treeBox .ec{margin:0 5 0 5;}
#treeBox .hasItems{font-weight:bold;height:20px;padding:3 6 0 6;margin:2px;cursor:hand;color:#555555;border:1px solid #fffffa;}
#treeBox .Items{height:20px;padding:3 6 0 6;margin:1px;cursor:hand;color:#555555;border:1px solid #fffffa;}
</style>
<base href=”http://vip.5d.cn/star/dstree/&#8221; />
<script>
//code by star 20003-4-7
var HC = “color:#990000;border:1px solid #cccccc”;
var SC = “background-color:#efefef;border:1px solid #cccccc;color:#000000;”;
var IO = null;
function initTree(){
     var rootn = document.all.menuXML.documentElement;
     var sd = 0;
     document.onselectstart = function(){return false;}
     document.all.treeBox.appendChi ld(createTree(rootn,sd));
}
function createTree(thisn,sd){
     var nodeObj = document.createElement(“span”);
     var upobj = document.createElement(“span”);
     with(upobj){
           style.marginLeft = sd*10;
           className = thisn.hasChildNodes()?”hasItems”:”Items”;
           innerHTML = “<img src=http://www.163design.net/x/b/expand.gif class=ec>” + thisn.getAttribute(“text”) +””;
          
           onmousedown = function(){
                if(event.button != 1) return;
                if(this.getAttribute(“cn”)){
                      this.setAttribute(“open”,!this.getAttribute(“open”));
                      this.cn.style.display = this.getAttribute(“open”)?”inline”:”none”;
                      this.all.tags(“img”)[0].src = this.getAttribute(“open”)?”http://www.163design.net/x/b/expand.gif&#8221;:”contract.gif”;
                }
                if(IO){
                      IO.runtimeStyle.cssText = “”;
                      IO.setAttribute(“selected”,false);
                }
                IO = this;
                this.setAttribute(“selected”,t rue);
                this.runtimeStyle.cssText = SC;
           }
           onmouseover = function(){
                if(this.getAttribute(“selected “))return;
                this.runtimeStyle.cssText = HC;
           }
           onmouseout = function(){
                if(this.getAttribute(“selected “))return;
                this.runtimeStyle.cssText = “”;
           }
           oncontextmenu = contextMenuHandle;
           onclick = clickHandle;
     }

     if(thisn.getAttribute(“treeId” ) != null){
           upobj.setAttribute(“treeId”,thisn.getAttribute(“treeId”));
     }
     if(thisn.getAttribute(“href”) != null){
           upobj.setAttribute(“href”,thisn.getAttribute(“href”));
     }
     if(thisn.getAttribute(“target” ) != null){
           upobj.setAttribute(“target”,thisn.getAttribute(“target”));
     }

[1] [2] 下一页  

欢迎大家阅读《XML+ JS创建树形菜单_xml,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:XML+ JS创建树形菜单_xml

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址