采用JavaScript+XML实现具有树形菜单功能的论坛侧边导航栏
来源:互联网 发布:信掌柜软件下载 编辑:程序博客网 时间:2024/05/17 23:35
核心页面代码:
(bbsMenu.htm)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> VsensBBS </TITLE><style>body,td{font:12px verdana; height:50px;}#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><script>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.appendChild(createTree(rootn,sd).childNodes[2]);}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=image/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")?"image/expand.gif":"image/collapse.gif"; } if(IO){ IO.runtimeStyle.cssText = ""; IO.setAttribute("selected",false); } IO = this; this.setAttribute("selected",true); 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")); } nodeObj.appendChild(upobj); nodeObj.insertAdjacentHTML("beforeEnd","<br>") if(thisn.hasChildNodes()){ var i; var nodes = thisn.childNodes; var cn = document.createElement("span"); upobj.setAttribute("cn",cn); if(thisn.getAttribute("open") != null){ upobj.setAttribute("open",(thisn.getAttribute("open")=="true")); upobj.getAttribute("cn").style.display = upobj.getAttribute("open")?"inline":"none"; if( !upobj.getAttribute("open"))upobj.all.tags("img")[0].src ="image/collapse.gif"; } for(i=0;i<nodes.length;cn.appendChild(createTree(nodes[i++],sd+1))); nodeObj.appendChild(cn); } else{ upobj.all.tags("img")[0].src ="image/endnode.gif"; } return nodeObj;}window.onload = initTree;</script><script>function contextMenuHandle(){ event.returnValue = false; var treeId = this.getAttribute("treeId"); // your code here}function clickHandle(){window.open(this.href,"mainFrame");}</script></HEAD><BODY><xml id=menuXML><?xml version="1.0" encoding="GB2312"?><DSTreeRoot text="华盛社区" open="true" href="http://" treeId="123"> <DSTree text="产品交流" open="false" href="" target="_self" treeId="12"> <DSTree text="产品交流子节点" href="http://www.baidu.com" target="_blank" treeId="4353" /> <DSTree text="产品交流子节点" href="http://www.jnunet.cn/assets" target="box" treeId="543543" /> <DSTree text="产品交流子节点" href="" target="box" treeId="543543" /> </DSTree> <DSTree text="产品销售" open="false" href="" treeId="213"> <DSTree text="产品销售子节点" href="http://www.baidu.com" treeId="4353" /> <DSTree text="产品销售子节点" href="" treeId="543543" /> </DSTree> <DSTree text="渠道物流" open="false" href="" treeId="432"> <DSTree text="渠道物流子节点" href="" treeId="4353" /> <DSTree text="渠道物流子节点" href="" treeId="543543" /> </DSTree> <DSTree text="市场推广" open="false" href="" target="box" treeId="213"> <DSTree text="市场推广子节点" href="" treeId="4353" /> <DSTree text="市场推广子节点" href="" treeId="543543" /> </DSTree></DSTreeRoot></xml><table style="position:absolute;left:0;top:0;"><tr><td id=treeBox style="width:250px;height:600px;;border:1px solid #cccccc;padding:45 3 3 5; background-image:url(image/bbsTitleBack.gif); background-position:top; background-repeat:repeat-x; padding-right:65px; " valign=top></td></tr></table></BODY></HTML>其中,
function clickHandle(){window.open(this.href,"mainFrame");}
为鼠标点击某一节点后执行的动作。全部代码来源于我近期的一个项目,客户要求论坛必须有侧边导航栏,我于是想到用框架来实现。"mainFrame"是主显框架的ID及name属性。读者可灵活修改。
附上框架全部代码及图片打包下载:
http://download.csdn.net/source/340556
- 采用JavaScript+XML实现具有树形菜单功能的论坛侧边导航栏
- javascript实现基于XML的导航功能
- jquery实现侧边栏手风琴三级导航菜单demo
- Android 侧边字母导航栏的实现
- 侧边栏导航布局的实现
- jQuery 实现侧边浮动导航菜单效果
- android slidingMenu 侧边栏菜单 的实现
- Ionic 侧边栏菜单的简单实现
- JavaScript+CSS实现经典的树形导航栏
- 可伸缩右侧边栏导航菜单
- android实现侧边导航栏
- CSS实现侧边栏导航
- Notes03:侧边导航菜单
- 使用SWRevealViewController实现侧边菜单功能详解
- 采用jquery+css实现极酷的下拉菜单导航
- 一个很简单的侧边栏导航实现
- bootstrap自定义样式-bootstrap侧边导航栏的实现
- 多叉树结合JavaScript树形控件实现无限级树形菜单(一种构建多级有序树形结构JSON(或XML)数据源的方法)
- 媳妇写给婆婆的一封惊世骇俗的信
- 2006世界杯32强人体彩绘队服样式(波兰)
- MD5加密算法(java)
- 2006世界杯32强人体彩绘队服样式(多哥)
- Java实现利用搜索引擎收集网址的程序
- 采用JavaScript+XML实现具有树形菜单功能的论坛侧边导航栏
- 2006世界杯32强人体彩绘队服样式(德国)
- spring aop学习的第一个例子
- 2006世界杯32强人体彩绘队服样式(法国)
- JavaServer Faces 1.2 入门,第 1 部分: 构建基本应用程序
- 2006世界杯32强人体彩绘队服样式(哥斯达黎加)
- 关于麦肯锡、埃森哲、IBM、普华永道的笑话
- 2006世界杯32强人体彩绘队服样式(捷克)
- 2006世界杯32强人体彩绘队服样式(荷兰)