一个XML+JS的菜单,好用

来源:互联网 发布:心情无人知 编辑:程序博客网 时间:2024/04/28 01:23
<HTML>
<HEAD>
<TITLE> Menu </TITLE>

<style>
body,td
{font:12px verdana}
#treemain
{background-color:#fffffa;}
#treemain .ec
{margin:0 5 0 5;}
#treemain .hasItems
{font-weight:bold;height:20px;padding:3 6 0 6;margin:2px;cursor:hand;color:#555555;border:1px solid #fffffa;}
#treemain .Items
{height:20px;padding:3 6 0 6;margin:1px;cursor:hand;color:#555555;border:1px solid #fffffa;}
</style>

<script>
//code by star 20003-4-7
//
debugger
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.treemain.appendChild(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=img/open.gif class=ec>" + thisn.getAttribute("text"+"";
        
        onmousedown 
= function(){
            
if(event.button != 1return;
            
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")?"img/open.gif":"img/closed.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 ="img/closed.gif";
        }

        
        
for(i=0;i<nodes.length;cn.appendChild(createTree(nodes[i++],sd+1)));
        nodeObj.appendChild(cn);
    }

    
else{
        upobj.all.tags(
"img")[0].src ="img/last.gif";
    }

    
return nodeObj;
}

window.onload 
= initTree;
</script>

<script>
function clickHandle(){
    
// your code here 
    if (this.getAttribute("target"==null)return;
    window.parent.frames.main.location 
= this.getAttribute("href");
}

function contextMenuHandle(){
    event.returnValue 
= false;
    
var treeId = this.getAttribute("treeId");
    
// your code here
}

</script>
</HEAD>
<BODY>
<xml id=menuXML>
<?xml version="1.0" encoding="GB2312"?>
<DSTreeRoot text="Daxon绩效考核系统" open="true" href="#" treeId="123">
    
    
<DSTree text="管理者设定" open="false" treeId="">
        
            
<DSTree text="考核期间设定" href="managementPa_Period.aspx" target="main" treeId="4353" />
            
<DSTree text="绩效层级设定" href="managementPa_Rank.aspx" target="main" treeId="543543" />
            
<DSTree text="进度查询" href="managementPa_Schedule.aspx" target="main" treeId="543543" />
        
    
</DSTree>

    
<DSTree text="员工自评" open="false" treeId="">
        
        
<DSTree text="填写考核表单" open="false" href="#"  treeId="213">
            
<DSTree text="Part1本期目标评核表" href="EmployeePa_Part1.aspx" target="main" treeId="4353" />
            
<DSTree text="Part2核心职能评核表" href="EmployeePa_Part2.aspx" target="main" treeId="543543" />
            
<DSTree text="Part3下期目标规划表" href="EmployeePa_Part3.aspx" target="main" treeId="543543" />
            
<DSTree text="Part4个人发展与建议表" href="EmployeePa_Part4.aspx" target="main" treeId="543543" />
        
</DSTree>
        
        
<DSTree text="修改年度目标规划" href="EmployeePA_MBOModify.aspx" target="main" treeId="4353" />
        
<DSTree text="查询员工自评" href="EmployeePA_SelfQurey.aspx" target="main" treeId="543543" />
    
</DSTree>
    
<DSTree text="主管考核" open="false" treeId="">
        
            
<DSTree text="直属部属考核" href="DirectorPa_BossAppr.aspx" target="main" treeId="4353" />
            
<DSTree text="所属员工绩效查询" href="DirectorPA_BossQry.aspx" target="main" treeId="543543" />
            
<DSTree text="MBO修改签核" href="DirectorPA_MBOAppr.aspx" target="main" treeId="543543" />
        
    
</DSTree>
    
<DSTree text="考核作业说明" open="false" treeId="">
        
    
</DSTree>
    
<DSTree text="回首页" open="false" href="default.aspx" target="_self" treeId="">
        
    
</DSTree>

</DSTreeRoot>
</xml>
<table style="position:absolute;left:10;top:10;">
<tr><td id=treemain style="width:220px;height:200px;border:1px solid #cccccc;padding:5 3 3 5;" valign=top></td></tr>

</table>
</BODY>
</HTML>
 
原创粉丝点击