高手请进:如何实现树型结构中的动态右键菜单?

时间:2022-02-03 11:56:46
我现在想在一个树型结构上实现右键菜单,要求给菜单中的功能传递一个参数例如树结点的编号,当右键点击某个结点N01时,进行点左键应进行的动作外,显示出右键菜单,选择菜单中的功能如删除时,将向后台某个程序传递一个参数N01,表示要删除的是编号为N01的结点,同理右击结点N02时选删除将删掉N02结点。

请高手帮忙解决!

一般的右键菜单在网页的所有位置点出来的都一样的,也就是什么前进后退查看源跳转等功能,不能征对页面的某个对象动态传一个参数。

6 个解决方案

#1


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>右键菜单</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<STYLE type=text/css>BODY {
FONT-SIZE: 9pt
}
TABLE {
FONT-SIZE: 9pt; MARGIN: 0px; CURSOR: default
}
TR {
HEIGHT: 20px
}
TR.over {
FONT-SIZE: 9pt; CURSOR: default; COLOR: #ffffff; BACKGROUND-COLOR: #66aadd
}
TR.out {
FONT-SIZE: 9pt; CURSOR: default; COLOR: #ffffff; BACKGROUND-COLOR: #336699
}
DIV.rm_div {
BORDER-RIGHT: #3377aa 2px outset; BORDER-TOP: #3377aa 2px outset; DISPLAY: none; FILTER: Alpha(Opacity='95'); BORDER-LEFT: #3377aa 2px outset; WIDTH: 0px; BORDER-BOTTOM: #3377aa 2px outset; POSITION: absolute; HEIGHT: 0px; BACKGROUND-COLOR: #336699
}
HR.sperator {
BORDER-RIGHT: #3377aa 1px inset; BORDER-TOP: #3377aa 1px inset; BORDER-LEFT: #3377aa 1px inset; BORDER-BOTTOM: #3377aa 1px inset
}
</STYLE>

<SCRIPT language=JScript>
  <!--
  function RightMenu()
  {
    this.AddExtendMenu=AddExtendMenu;
    this.AddItem=AddItem;
    this.GetMenu=GetMenu;
    this.HideAll=HideAll;
    this.I_OnMouseOver=I_OnMouseOver;
    this.I_OnMouseOut=I_OnMouseOut;
    this.I_OnMouseUp=I_OnMouseUp;
    this.P_OnMouseOver=P_OnMouseOver;
    this.P_OnMouseOut=P_OnMouseOut;
    A_rbpm = new Array();
    HTMLstr  = "";
    HTMLstr += "<!-- RightButton PopMenu -->\n";
    HTMLstr += "\n";
    HTMLstr += "<!-- PopMenu Starts -->\n";
    HTMLstr += "<div id='E_rbpm' class='rm_div'>\n";
                        // rbpm = right button pop menu
    HTMLstr += "<table width='100%' border='0' cellspacing='0'>\n";
    HTMLstr += "<!-- Insert A Extend Menu or Item On Here For E_rbpm -->\n";
    HTMLstr += "</table>\n";
    HTMLstr += "</div>\n";
    HTMLstr += "<!-- Insert A Extend_Menu Area on Here For E_rbpm -->";
    HTMLstr += "\n";
    HTMLstr += "<!-- PopMenu Ends -->\n";
  }
  function AddExtendMenu(id,name,parent)
  {
    var TempStr = "";
    if(HTMLstr.indexOf("<!-- Extend Menu Area : E_"+id+" -->") != -1)
    {
      alert("E_"+id+"already exist!");
      return;
    }
    eval("A_"+parent+".length++");
    eval("A_"+parent+"[A_"+parent+".length-1] = id");  // 将此项注册到父菜单项的ID数组中去
    TempStr += "<!-- Extend Menu Area : E_"+id+" -->\n";
    TempStr += "<div id='E_"+id+"' class='rm_div'>\n";
    TempStr += "<table width='100%' border='0' cellspacing='0'>\n";
    TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+id+" -->";
    TempStr += "</table>\n";
    TempStr += "</div>\n";
    TempStr += "<!-- Insert A Extend_Menu Area on Here For E_"+id+" -->";
    TempStr += "<!-- Insert A Extend_Menu Area on Here For E_"+parent+" -->";
    HTMLstr = HTMLstr.replace("<!-- Insert A Extend_Menu Area on Here For E_"+parent+" -->",TempStr);

    
    eval("A_"+id+" = new Array()");
    TempStr  = "";
    TempStr += "<!-- Extend Item : P_"+id+" -->\n";
    TempStr += "<tr id='P_"+id+"' class='out'";
    TempStr += " onmouseover='P_OnMouseOver(\""+id+"\",\""+parent+"\")'";
    TempStr += " onmouseout='P_OnMouseOut(\""+id+"\",\""+parent+"\")'";
    TempStr += " onmouseup=window.event.cancelBubble=true;";
    TempStr += " onclick=window.event.cancelBubble=true;";
    TempStr += "><td nowrap>";
    TempStr += "&nbsp;&nbsp;&nbsp;"+name+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td style='font-family: webdings; text-align: right;'>";
    TempStr += "</td></tr>\n";
    TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->";
    HTMLstr = HTMLstr.replace("<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->",TempStr);
  }

function AddItem(id,name,parent,location)
  {
    var TempStr = "";
    var ItemStr = "<!-- ITEM : I_"+id+" -->";
    if(id == "sperator")
    {
      TempStr += ItemStr+"\n";
      TempStr += "<tr style='height: 3;' class='out' onclick='window.event.cancelBubble=true;' onmouseup='window.event.cancelBubble=true;'><td colspan='2'><hr class='sperator'></td></tr>";
      TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->";
      HTMLstr = HTMLstr.replace("<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->",TempStr);
      return;
    }
    if(HTMLstr.indexOf(ItemStr) != -1)
    {
      alert("I_"+id+"already exist!");
      return;
    }
    TempStr += ItemStr+"\n";
    TempStr += "<tr id='I_"+id+"' class='out'";
    TempStr += " onmouseover='I_OnMouseOver(\""+id+"\",\""+parent+"\")'";
    TempStr += " onmouseout='I_OnMouseOut(\""+id+"\")'";
    TempStr += " onclick='window.event.cancelBubble=true;'";
    if(location == null)
      TempStr += " onmouseup='I_OnMouseUp(\""+id+"\",\""+parent+"\",null)'";
    else
      TempStr += " onmouseup='I_OnMouseUp(\""+id+"\",\""+parent+"\",\""+location+"\")'";
    TempStr += "><td nowrap>";
    TempStr += "&nbsp;&nbsp;&nbsp;"+name+"&nbsp;&nbsp;&nbsp;";
    TempStr += "</td><td></td></tr>\n";
    TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->";
    HTMLstr = HTMLstr.replace("<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->",TempStr);
  }
  function GetMenu()
  {
    return HTMLstr;
  }
  function I_OnMouseOver(id,parent)
  {
    var Item;
    if(parent != "rbpm")
    {
      var ParentItem;
      ParentItem = eval("P_"+parent);
      ParentItem.className="over";
    }
    Item = eval("I_"+id);
    Item.className="over";
    HideAll(parent,1);
  }
  function I_OnMouseOut(id)
  {
    var Item;
    Item = eval("I_"+id);
    Item.className="out";
  }
  function I_OnMouseUp(id,parent,location)
  {
    var ParentMenu;
    window.event.cancelBubble=true;
    OnClick();
    ParentMenu = eval("E_"+parent);
    ParentMenu.display="none";
    if(location == null)
      eval("Do_"+id+"()");
    else
      window.open(location);
  }
  function P_OnMouseOver(id,parent)
  {
    var Item;
    var Extend;
    var Parent;
    if(parent != "rbpm")
    {
      var ParentItem;
      ParentItem = eval("P_"+parent);
      ParentItem.className="over";
    }
    HideAll(parent,1);
    Item = eval("P_"+id);
    Extend = eval("E_"+id);
    Parent = eval("E_"+parent);
    Item.className="over";
    Extend.style.display="block";

#2



    Extend.style.posLeft=document.body.scrollLeft+Parent.offsetLeft+Parent.offsetWidth-4;
    if(Extend.style.posLeft+Extend.offsetWidth > document.body.scrollLeft+document.body.clientWidth)
        Extend.style.posLeft=Extend.style.posLeft-Parent.offsetWidth-Extend.offsetWidth+8;
    if(Extend.style.posLeft < 0) Extend.style.posLeft=document.body.scrollLeft+Parent.offsetLeft+Parent.offsetWidth;
    Extend.style.posTop=Parent.offsetTop+Item.offsetTop;
    if(Extend.style.posTop+Extend.offsetHeight > document.body.scrollTop+document.body.clientHeight)
      Extend.style.posTop=document.body.scrollTop+document.body.clientHeight-Extend.offsetHeight;
    if(Extend.style.posTop < 0) Extend.style.posTop=0;
  }
  function P_OnMouseOut(id,parent)
  {
  }
  function HideAll(id,flag)
  {
    var Area;
    var Temp;
    var i;
    if(!flag)
    {
      Temp = eval("E_"+id);
      Temp.style.display="none";
    }
    Area = eval("A_"+id);
    if(Area.length)
    {
      for(i=0; i < Area.length; i++)
      {
        HideAll(Area[i],0);
        Temp = eval("E_"+Area[i]);
        Temp.style.display="none";
        Temp = eval("P_"+Area[i]);
        Temp.className="out";
      }
    }
  }

  document.onmouseup=OnMouseUp;
  document.onclick=OnClick;
  function OnMouseUp()
  {
    if(window.event.button == 2)
    {
      var PopMenu;
      PopMenu = eval("E_rbpm");
      HideAll("rbpm",0);
      PopMenu.style.display="block";
      PopMenu.style.posLeft=document.body.scrollLeft+window.event.clientX;
      PopMenu.style.posTop=document.body.scrollTop+window.event.clientY;
      if(PopMenu.style.posLeft+PopMenu.offsetWidth > document.body.scrollLeft+document.body.clientWidth)
        PopMenu.style.posLeft=document.body.scrollLeft+document.body.clientWidth-PopMenu.offsetWidth;
      if(PopMenu.style.posLeft < 0) PopMenu.style.posLeft=0;
      if(PopMenu.style.posTop+PopMenu.offsetHeight > document.body.scrollTop+document.body.clientHeight)
        PopMenu.style.posTop=document.body.scrollTop+document.body.clientHeight-PopMenu.offsetHeight;
      if(PopMenu.style.posTop < 0) PopMenu.style.posTop=0;
    }
  }
  function OnClick()
  {
    HideAll("rbpm",0);
  }
  // Add Your Function on following
  function Do_viewcode(){window.location="view-source:"+window.location.href;}
  function Do_help(){window.showHelp(window.location);}
  function Do_exit() {window.close();}
  function Do_refresh() {window.location.reload();}
  function Do_back() {history.back();}
  function Do_forward() {history.forward();}
  function Do_author(){alert("姓名:杨俊\n网名:风舞影天(Snwcwt)\nE_mail:snwcwt.com@263.net\n个人主页:http://202.115.147.160/snwcwt(正在制作中)\n")}
  -->
</SCRIPT>

#3


<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY oncontextmenu=window.event.returnValue=false>
<DIV id=snwcwt>&nbsp;</DIV>
<SCRIPT language=JScript>
  <!--
  var menu = new RightMenu();
  menu.AddExtendMenu("location","我的链接","rbpm");
    menu.AddExtendMenu("lscit","四川工业学院校园网","location");
      menu.AddItem("scit_scit","川工首页","lscit","http://www.scit.edu.cn");
      menu.AddItem("scit_lib","川工图书馆","lscit","http://202.115.151.46");
      menu.AddItem("sperator","","lscit",null);
      menu.AddItem("scit_century","世纪学苑","lscit","http://202.115.148.230/");
      menu.AddItem("scit_the5","第五空间","lscit","http://the5.scit.edu.cn/");
      menu.AddItem("scit_lianyi","联谊网站","lscit","http://202.115.148.240");
      menu.AddItem("scit_message","信息导报","lscit","http://202.115.151.114/xx");
      menu.AddItem("scit_student","书生之家川工境象","lscit","http://202.115.151.100");
      menu.AddItem("sperator","","lscit",null);
      menu.AddItem("scit_bbs","川工BBS","lscit","http://202.115.144.32");
      menu.AddItem("scit_cbbs","世纪学苑BBS","lscit","http://202.115.144.37");
    menu.AddExtendMenu("stunet","学生网站","location");
      menu.AddItem("stu_century","世纪学苑","stunet","http://202.115.148.230/");
      menu.AddItem("stu_wjl","望江楼","stunet","http://wjl.scu.edu.cn");
      menu.AddItem("stu_freedim","*天地","stunet","http://www.freedim.net/");
      menu.AddItem("stu_stuhome","学生之家","stunet","http://www.stuhome.net");
      menu.AddItem("stu_rw","人文网","stunet","http://www.rw.uestc.edu.cn/");
      menu.AddItem("stu_the5","第五空间","stunet","http://the5.scit.edu.cn/");
      menu.AddItem("stu_flying","我心飞扬","stunet","http://flying.swpi.edu.cn/");
      menu.AddItem("stu_21cn","21CN校园网","stunet","http://www.21cn.edu.cn/");
      menu.AddItem("stu_yaguo","网虫乐园","stunet","http://www.yaguo.com/");
    menu.AddItem("sperator","","location",null);
    menu.AddExtendMenu("computer","电脑类网站","location");
      menu.AddExtendMenu("C_all","综合性网站","computer");
        menu.AddItem("ca_yesky","天极网","C_all","http://www.yesky.com");
      menu.AddExtendMenu("C_program","程序员网站","computer");
        menu.AddItem("cp_program","中国程序员网站","C_program","http://www.chinaprogrammer.com/");
        menu.AddItem("sperator","","C_program",null);
        menu.AddItem("cp_51js","无忧脚本","C_program","http://www.51js.com/");
        menu.AddItem("sperator","","C_program",null);
        menu.AddItem("cp_active","中国动感技术网络","C_program","http://www.chinaasp.com/active/");
        menu.AddItem("cp_aspcn","ASP中华网","C_program","http://www.aspcn.com/");
        menu.AddItem("cp_aspx","中国ASP联盟","C_program","http://www.chinaspx.com/");
      menu.AddExtendMenu("C_magzine","杂志网站","computer");
        menu.AddItem("cm_cpcw","电脑报","C_magzine","http://www.cpcw.com");
        menu.AddItem("cm_cfan","电脑爱好者","C_magzine","http://www.cfan.net.cn");
        menu.AddItem("cm_popsoft","大众软件","C_magzine","http://www.popsoft.com");
      menu.AddExtendMenu("C_luntan","技术性论坛","computer");
        menu.AddItem("cl_chinaasp","ChinaASP论坛","C_luntan","http://www.chinaasp.com/sqlbbs");
      menu.AddExtendMenu("C_book","书籍下载","computer");
        menu.AddItem("cb_huachu","华储网上书店","C_book","http://www.huachu.com.cn/");
    menu.AddExtendMenu("hacker","黑客天地","location");
      menu.AddItem("hk_honker","<font style='color: #ff0000;'>中国红客联盟</font>","hacker","http://www.cnhonker.com");
    menu.AddItem("sperator","","location",null);
    menu.AddExtendMenu("lmovie","影视天地","location");
      menu.AddItem("mov_wcums","华西网上影院","lmovie","http://202.115.100.8/");
    menu.AddExtendMenu("lmusic","音乐空间","location");
      menu.AddItem("mus_tyfo","天虎音乐网","lmusic","http://music.tyfo.com/");
      menu.AddItem("mus_langqin","浪琴音乐","lmusic","http://www.langqin.net/");
      menu.AddItem("mus_wcums","华西音乐空间","lmusic","http://music.wcums.edu.cn/");
    menu.AddExtendMenu("lmud","泥巴链接","location");
      menu.AddItem("lmud_mudking","泥巴大王","lmud","http://www.mudking.com");
      menu.AddItem("lmud_justmud","泥巴城堡","lmud","http://www.justmud.com");
      menu.AddItem("lmud_mudall","世界泥巴资源","lmud","http://www.mudall.com");
      menu.AddItem("lmud_yaguo","泥潭风云","lmud","http://202.114.98.14/mud/");
    menu.AddItem("sperator","","location",null);
    menu.AddExtendMenu("lemail","电子邮局","location");
      menu.AddItem("email_263","263免费电子邮局","lemail","http://freemail.263.net");
    menu.AddExtendMenu("collections","综合性网站","location");
      menu.AddItem("coll_chinaren","中国人网站","collections","http://www.chinaren.com/");
      menu.AddItem("coll_etang","亿唐网站","collections","http://www.etang.com/");
      menu.AddItem("coll_263","263首都在线","collections","http://www.263.net/");
  menu.AddExtendMenu("leave","离开","rbpm");
    menu.AddItem("forward","前进","leave",null);
    menu.AddItem("back","后退","leave",null);
    menu.AddItem("sperator","","leave",null);
    menu.AddItem("exit","退出","leave",null);
  menu.AddItem("viewcode","查看源代码","rbpm",null);
  menu.AddItem("refresh","刷新","rbpm",null);
  menu.AddItem("sperator","","rbpm",null);
  menu.AddItem("help","帮助","rbpm",null);
  menu.AddItem("sperator","","rbpm",null);
  menu.AddItem("author","<font style='color: #ff0000'>关于作者</font>","rbpm",null);
  document.writeln(menu.GetMenu());
  -->
  </SCRIPT>
</BODY></HTML>

#4


1. 定义一系列不同的菜单,如 A.xml, B.xml, C.xml...

2. 定义一个转换XML->Html的文档menu.xslt,作用是把xml转换成html代码

3. 每个树结点添加一个Type属性如 Type="A"

4. 根据type属性决定弹出哪个菜单

此方案可扩展,仅仅需要添加一个新的xml菜单即可。

#5


To :  blueice2002(蓝冰) 
  老大你好象没看明白我的意思

To : asklxf(xuefeng)
  我不太想用XML来解决这个问题,实质上这个问题的焦点是当右键点击某一页面元素如div,span,input什么的我们是否可以获取该元素的信息如id,通常情况,自定义的右键菜单中只能获取点击的位置坐标x,y
是否能解决这个问题,请指点!

#6


文件1:
<OBJECT 
id=menu1 
onmouseover="menu1.style.display=''" 
style=" POSITION: ABSOLUTE;DISPLAY: none; Z-INDEX: 1000;  HEIGHT: 200px" 
onmouseout="menu1.style.display='none'" 
type=text/x-scriptlet 
data=caidan.htm 
VIEWASTEXT>
</OBJECT>
<SCRIPT LANGUAGE=vbscript >
function document_oncontextmenu()
document_oncontextmenu=false
menu1.style.LEFT=window.event.x 
menu1.style.TOP=window.event.y 
menu1.style.display=""
end function
</SCRIPT>
文件2:
caidan.htm 
<div style='position:absolute;left:0;top:0;width:152;height:200;font:14;color:white;background:black;border:1 solid black'>
<div onclick="alert(this.innerText)">菜单1</div>
<div onclick="alert(this.innerText)">菜单2</div>
<div onclick="alert(this.innerText)">菜单3</div>
<div onclick="alert(this.innerText)">菜单4</div>
<div onclick="alert(this.innerText)">菜单5</div>
<div onclick="alert(this.innerText)">菜单6</div>
<div onclick="alert(this.innerText)">菜单7</div>
</div>
演示:
www.adr.gov.cn/download/Rmenu.htm
这个菜单还有个好处,不会被<select>标签遮挡哦!~~
一般div不会有这个效果

#1


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>右键菜单</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<STYLE type=text/css>BODY {
FONT-SIZE: 9pt
}
TABLE {
FONT-SIZE: 9pt; MARGIN: 0px; CURSOR: default
}
TR {
HEIGHT: 20px
}
TR.over {
FONT-SIZE: 9pt; CURSOR: default; COLOR: #ffffff; BACKGROUND-COLOR: #66aadd
}
TR.out {
FONT-SIZE: 9pt; CURSOR: default; COLOR: #ffffff; BACKGROUND-COLOR: #336699
}
DIV.rm_div {
BORDER-RIGHT: #3377aa 2px outset; BORDER-TOP: #3377aa 2px outset; DISPLAY: none; FILTER: Alpha(Opacity='95'); BORDER-LEFT: #3377aa 2px outset; WIDTH: 0px; BORDER-BOTTOM: #3377aa 2px outset; POSITION: absolute; HEIGHT: 0px; BACKGROUND-COLOR: #336699
}
HR.sperator {
BORDER-RIGHT: #3377aa 1px inset; BORDER-TOP: #3377aa 1px inset; BORDER-LEFT: #3377aa 1px inset; BORDER-BOTTOM: #3377aa 1px inset
}
</STYLE>

<SCRIPT language=JScript>
  <!--
  function RightMenu()
  {
    this.AddExtendMenu=AddExtendMenu;
    this.AddItem=AddItem;
    this.GetMenu=GetMenu;
    this.HideAll=HideAll;
    this.I_OnMouseOver=I_OnMouseOver;
    this.I_OnMouseOut=I_OnMouseOut;
    this.I_OnMouseUp=I_OnMouseUp;
    this.P_OnMouseOver=P_OnMouseOver;
    this.P_OnMouseOut=P_OnMouseOut;
    A_rbpm = new Array();
    HTMLstr  = "";
    HTMLstr += "<!-- RightButton PopMenu -->\n";
    HTMLstr += "\n";
    HTMLstr += "<!-- PopMenu Starts -->\n";
    HTMLstr += "<div id='E_rbpm' class='rm_div'>\n";
                        // rbpm = right button pop menu
    HTMLstr += "<table width='100%' border='0' cellspacing='0'>\n";
    HTMLstr += "<!-- Insert A Extend Menu or Item On Here For E_rbpm -->\n";
    HTMLstr += "</table>\n";
    HTMLstr += "</div>\n";
    HTMLstr += "<!-- Insert A Extend_Menu Area on Here For E_rbpm -->";
    HTMLstr += "\n";
    HTMLstr += "<!-- PopMenu Ends -->\n";
  }
  function AddExtendMenu(id,name,parent)
  {
    var TempStr = "";
    if(HTMLstr.indexOf("<!-- Extend Menu Area : E_"+id+" -->") != -1)
    {
      alert("E_"+id+"already exist!");
      return;
    }
    eval("A_"+parent+".length++");
    eval("A_"+parent+"[A_"+parent+".length-1] = id");  // 将此项注册到父菜单项的ID数组中去
    TempStr += "<!-- Extend Menu Area : E_"+id+" -->\n";
    TempStr += "<div id='E_"+id+"' class='rm_div'>\n";
    TempStr += "<table width='100%' border='0' cellspacing='0'>\n";
    TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+id+" -->";
    TempStr += "</table>\n";
    TempStr += "</div>\n";
    TempStr += "<!-- Insert A Extend_Menu Area on Here For E_"+id+" -->";
    TempStr += "<!-- Insert A Extend_Menu Area on Here For E_"+parent+" -->";
    HTMLstr = HTMLstr.replace("<!-- Insert A Extend_Menu Area on Here For E_"+parent+" -->",TempStr);

    
    eval("A_"+id+" = new Array()");
    TempStr  = "";
    TempStr += "<!-- Extend Item : P_"+id+" -->\n";
    TempStr += "<tr id='P_"+id+"' class='out'";
    TempStr += " onmouseover='P_OnMouseOver(\""+id+"\",\""+parent+"\")'";
    TempStr += " onmouseout='P_OnMouseOut(\""+id+"\",\""+parent+"\")'";
    TempStr += " onmouseup=window.event.cancelBubble=true;";
    TempStr += " onclick=window.event.cancelBubble=true;";
    TempStr += "><td nowrap>";
    TempStr += "&nbsp;&nbsp;&nbsp;"+name+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td style='font-family: webdings; text-align: right;'>";
    TempStr += "</td></tr>\n";
    TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->";
    HTMLstr = HTMLstr.replace("<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->",TempStr);
  }

function AddItem(id,name,parent,location)
  {
    var TempStr = "";
    var ItemStr = "<!-- ITEM : I_"+id+" -->";
    if(id == "sperator")
    {
      TempStr += ItemStr+"\n";
      TempStr += "<tr style='height: 3;' class='out' onclick='window.event.cancelBubble=true;' onmouseup='window.event.cancelBubble=true;'><td colspan='2'><hr class='sperator'></td></tr>";
      TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->";
      HTMLstr = HTMLstr.replace("<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->",TempStr);
      return;
    }
    if(HTMLstr.indexOf(ItemStr) != -1)
    {
      alert("I_"+id+"already exist!");
      return;
    }
    TempStr += ItemStr+"\n";
    TempStr += "<tr id='I_"+id+"' class='out'";
    TempStr += " onmouseover='I_OnMouseOver(\""+id+"\",\""+parent+"\")'";
    TempStr += " onmouseout='I_OnMouseOut(\""+id+"\")'";
    TempStr += " onclick='window.event.cancelBubble=true;'";
    if(location == null)
      TempStr += " onmouseup='I_OnMouseUp(\""+id+"\",\""+parent+"\",null)'";
    else
      TempStr += " onmouseup='I_OnMouseUp(\""+id+"\",\""+parent+"\",\""+location+"\")'";
    TempStr += "><td nowrap>";
    TempStr += "&nbsp;&nbsp;&nbsp;"+name+"&nbsp;&nbsp;&nbsp;";
    TempStr += "</td><td></td></tr>\n";
    TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->";
    HTMLstr = HTMLstr.replace("<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->",TempStr);
  }
  function GetMenu()
  {
    return HTMLstr;
  }
  function I_OnMouseOver(id,parent)
  {
    var Item;
    if(parent != "rbpm")
    {
      var ParentItem;
      ParentItem = eval("P_"+parent);
      ParentItem.className="over";
    }
    Item = eval("I_"+id);
    Item.className="over";
    HideAll(parent,1);
  }
  function I_OnMouseOut(id)
  {
    var Item;
    Item = eval("I_"+id);
    Item.className="out";
  }
  function I_OnMouseUp(id,parent,location)
  {
    var ParentMenu;
    window.event.cancelBubble=true;
    OnClick();
    ParentMenu = eval("E_"+parent);
    ParentMenu.display="none";
    if(location == null)
      eval("Do_"+id+"()");
    else
      window.open(location);
  }
  function P_OnMouseOver(id,parent)
  {
    var Item;
    var Extend;
    var Parent;
    if(parent != "rbpm")
    {
      var ParentItem;
      ParentItem = eval("P_"+parent);
      ParentItem.className="over";
    }
    HideAll(parent,1);
    Item = eval("P_"+id);
    Extend = eval("E_"+id);
    Parent = eval("E_"+parent);
    Item.className="over";
    Extend.style.display="block";

#2



    Extend.style.posLeft=document.body.scrollLeft+Parent.offsetLeft+Parent.offsetWidth-4;
    if(Extend.style.posLeft+Extend.offsetWidth > document.body.scrollLeft+document.body.clientWidth)
        Extend.style.posLeft=Extend.style.posLeft-Parent.offsetWidth-Extend.offsetWidth+8;
    if(Extend.style.posLeft < 0) Extend.style.posLeft=document.body.scrollLeft+Parent.offsetLeft+Parent.offsetWidth;
    Extend.style.posTop=Parent.offsetTop+Item.offsetTop;
    if(Extend.style.posTop+Extend.offsetHeight > document.body.scrollTop+document.body.clientHeight)
      Extend.style.posTop=document.body.scrollTop+document.body.clientHeight-Extend.offsetHeight;
    if(Extend.style.posTop < 0) Extend.style.posTop=0;
  }
  function P_OnMouseOut(id,parent)
  {
  }
  function HideAll(id,flag)
  {
    var Area;
    var Temp;
    var i;
    if(!flag)
    {
      Temp = eval("E_"+id);
      Temp.style.display="none";
    }
    Area = eval("A_"+id);
    if(Area.length)
    {
      for(i=0; i < Area.length; i++)
      {
        HideAll(Area[i],0);
        Temp = eval("E_"+Area[i]);
        Temp.style.display="none";
        Temp = eval("P_"+Area[i]);
        Temp.className="out";
      }
    }
  }

  document.onmouseup=OnMouseUp;
  document.onclick=OnClick;
  function OnMouseUp()
  {
    if(window.event.button == 2)
    {
      var PopMenu;
      PopMenu = eval("E_rbpm");
      HideAll("rbpm",0);
      PopMenu.style.display="block";
      PopMenu.style.posLeft=document.body.scrollLeft+window.event.clientX;
      PopMenu.style.posTop=document.body.scrollTop+window.event.clientY;
      if(PopMenu.style.posLeft+PopMenu.offsetWidth > document.body.scrollLeft+document.body.clientWidth)
        PopMenu.style.posLeft=document.body.scrollLeft+document.body.clientWidth-PopMenu.offsetWidth;
      if(PopMenu.style.posLeft < 0) PopMenu.style.posLeft=0;
      if(PopMenu.style.posTop+PopMenu.offsetHeight > document.body.scrollTop+document.body.clientHeight)
        PopMenu.style.posTop=document.body.scrollTop+document.body.clientHeight-PopMenu.offsetHeight;
      if(PopMenu.style.posTop < 0) PopMenu.style.posTop=0;
    }
  }
  function OnClick()
  {
    HideAll("rbpm",0);
  }
  // Add Your Function on following
  function Do_viewcode(){window.location="view-source:"+window.location.href;}
  function Do_help(){window.showHelp(window.location);}
  function Do_exit() {window.close();}
  function Do_refresh() {window.location.reload();}
  function Do_back() {history.back();}
  function Do_forward() {history.forward();}
  function Do_author(){alert("姓名:杨俊\n网名:风舞影天(Snwcwt)\nE_mail:snwcwt.com@263.net\n个人主页:http://202.115.147.160/snwcwt(正在制作中)\n")}
  -->
</SCRIPT>

#3


<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY oncontextmenu=window.event.returnValue=false>
<DIV id=snwcwt>&nbsp;</DIV>
<SCRIPT language=JScript>
  <!--
  var menu = new RightMenu();
  menu.AddExtendMenu("location","我的链接","rbpm");
    menu.AddExtendMenu("lscit","四川工业学院校园网","location");
      menu.AddItem("scit_scit","川工首页","lscit","http://www.scit.edu.cn");
      menu.AddItem("scit_lib","川工图书馆","lscit","http://202.115.151.46");
      menu.AddItem("sperator","","lscit",null);
      menu.AddItem("scit_century","世纪学苑","lscit","http://202.115.148.230/");
      menu.AddItem("scit_the5","第五空间","lscit","http://the5.scit.edu.cn/");
      menu.AddItem("scit_lianyi","联谊网站","lscit","http://202.115.148.240");
      menu.AddItem("scit_message","信息导报","lscit","http://202.115.151.114/xx");
      menu.AddItem("scit_student","书生之家川工境象","lscit","http://202.115.151.100");
      menu.AddItem("sperator","","lscit",null);
      menu.AddItem("scit_bbs","川工BBS","lscit","http://202.115.144.32");
      menu.AddItem("scit_cbbs","世纪学苑BBS","lscit","http://202.115.144.37");
    menu.AddExtendMenu("stunet","学生网站","location");
      menu.AddItem("stu_century","世纪学苑","stunet","http://202.115.148.230/");
      menu.AddItem("stu_wjl","望江楼","stunet","http://wjl.scu.edu.cn");
      menu.AddItem("stu_freedim","*天地","stunet","http://www.freedim.net/");
      menu.AddItem("stu_stuhome","学生之家","stunet","http://www.stuhome.net");
      menu.AddItem("stu_rw","人文网","stunet","http://www.rw.uestc.edu.cn/");
      menu.AddItem("stu_the5","第五空间","stunet","http://the5.scit.edu.cn/");
      menu.AddItem("stu_flying","我心飞扬","stunet","http://flying.swpi.edu.cn/");
      menu.AddItem("stu_21cn","21CN校园网","stunet","http://www.21cn.edu.cn/");
      menu.AddItem("stu_yaguo","网虫乐园","stunet","http://www.yaguo.com/");
    menu.AddItem("sperator","","location",null);
    menu.AddExtendMenu("computer","电脑类网站","location");
      menu.AddExtendMenu("C_all","综合性网站","computer");
        menu.AddItem("ca_yesky","天极网","C_all","http://www.yesky.com");
      menu.AddExtendMenu("C_program","程序员网站","computer");
        menu.AddItem("cp_program","中国程序员网站","C_program","http://www.chinaprogrammer.com/");
        menu.AddItem("sperator","","C_program",null);
        menu.AddItem("cp_51js","无忧脚本","C_program","http://www.51js.com/");
        menu.AddItem("sperator","","C_program",null);
        menu.AddItem("cp_active","中国动感技术网络","C_program","http://www.chinaasp.com/active/");
        menu.AddItem("cp_aspcn","ASP中华网","C_program","http://www.aspcn.com/");
        menu.AddItem("cp_aspx","中国ASP联盟","C_program","http://www.chinaspx.com/");
      menu.AddExtendMenu("C_magzine","杂志网站","computer");
        menu.AddItem("cm_cpcw","电脑报","C_magzine","http://www.cpcw.com");
        menu.AddItem("cm_cfan","电脑爱好者","C_magzine","http://www.cfan.net.cn");
        menu.AddItem("cm_popsoft","大众软件","C_magzine","http://www.popsoft.com");
      menu.AddExtendMenu("C_luntan","技术性论坛","computer");
        menu.AddItem("cl_chinaasp","ChinaASP论坛","C_luntan","http://www.chinaasp.com/sqlbbs");
      menu.AddExtendMenu("C_book","书籍下载","computer");
        menu.AddItem("cb_huachu","华储网上书店","C_book","http://www.huachu.com.cn/");
    menu.AddExtendMenu("hacker","黑客天地","location");
      menu.AddItem("hk_honker","<font style='color: #ff0000;'>中国红客联盟</font>","hacker","http://www.cnhonker.com");
    menu.AddItem("sperator","","location",null);
    menu.AddExtendMenu("lmovie","影视天地","location");
      menu.AddItem("mov_wcums","华西网上影院","lmovie","http://202.115.100.8/");
    menu.AddExtendMenu("lmusic","音乐空间","location");
      menu.AddItem("mus_tyfo","天虎音乐网","lmusic","http://music.tyfo.com/");
      menu.AddItem("mus_langqin","浪琴音乐","lmusic","http://www.langqin.net/");
      menu.AddItem("mus_wcums","华西音乐空间","lmusic","http://music.wcums.edu.cn/");
    menu.AddExtendMenu("lmud","泥巴链接","location");
      menu.AddItem("lmud_mudking","泥巴大王","lmud","http://www.mudking.com");
      menu.AddItem("lmud_justmud","泥巴城堡","lmud","http://www.justmud.com");
      menu.AddItem("lmud_mudall","世界泥巴资源","lmud","http://www.mudall.com");
      menu.AddItem("lmud_yaguo","泥潭风云","lmud","http://202.114.98.14/mud/");
    menu.AddItem("sperator","","location",null);
    menu.AddExtendMenu("lemail","电子邮局","location");
      menu.AddItem("email_263","263免费电子邮局","lemail","http://freemail.263.net");
    menu.AddExtendMenu("collections","综合性网站","location");
      menu.AddItem("coll_chinaren","中国人网站","collections","http://www.chinaren.com/");
      menu.AddItem("coll_etang","亿唐网站","collections","http://www.etang.com/");
      menu.AddItem("coll_263","263首都在线","collections","http://www.263.net/");
  menu.AddExtendMenu("leave","离开","rbpm");
    menu.AddItem("forward","前进","leave",null);
    menu.AddItem("back","后退","leave",null);
    menu.AddItem("sperator","","leave",null);
    menu.AddItem("exit","退出","leave",null);
  menu.AddItem("viewcode","查看源代码","rbpm",null);
  menu.AddItem("refresh","刷新","rbpm",null);
  menu.AddItem("sperator","","rbpm",null);
  menu.AddItem("help","帮助","rbpm",null);
  menu.AddItem("sperator","","rbpm",null);
  menu.AddItem("author","<font style='color: #ff0000'>关于作者</font>","rbpm",null);
  document.writeln(menu.GetMenu());
  -->
  </SCRIPT>
</BODY></HTML>

#4


1. 定义一系列不同的菜单,如 A.xml, B.xml, C.xml...

2. 定义一个转换XML->Html的文档menu.xslt,作用是把xml转换成html代码

3. 每个树结点添加一个Type属性如 Type="A"

4. 根据type属性决定弹出哪个菜单

此方案可扩展,仅仅需要添加一个新的xml菜单即可。

#5


To :  blueice2002(蓝冰) 
  老大你好象没看明白我的意思

To : asklxf(xuefeng)
  我不太想用XML来解决这个问题,实质上这个问题的焦点是当右键点击某一页面元素如div,span,input什么的我们是否可以获取该元素的信息如id,通常情况,自定义的右键菜单中只能获取点击的位置坐标x,y
是否能解决这个问题,请指点!

#6


文件1:
<OBJECT 
id=menu1 
onmouseover="menu1.style.display=''" 
style=" POSITION: ABSOLUTE;DISPLAY: none; Z-INDEX: 1000;  HEIGHT: 200px" 
onmouseout="menu1.style.display='none'" 
type=text/x-scriptlet 
data=caidan.htm 
VIEWASTEXT>
</OBJECT>
<SCRIPT LANGUAGE=vbscript >
function document_oncontextmenu()
document_oncontextmenu=false
menu1.style.LEFT=window.event.x 
menu1.style.TOP=window.event.y 
menu1.style.display=""
end function
</SCRIPT>
文件2:
caidan.htm 
<div style='position:absolute;left:0;top:0;width:152;height:200;font:14;color:white;background:black;border:1 solid black'>
<div onclick="alert(this.innerText)">菜单1</div>
<div onclick="alert(this.innerText)">菜单2</div>
<div onclick="alert(this.innerText)">菜单3</div>
<div onclick="alert(this.innerText)">菜单4</div>
<div onclick="alert(this.innerText)">菜单5</div>
<div onclick="alert(this.innerText)">菜单6</div>
<div onclick="alert(this.innerText)">菜单7</div>
</div>
演示:
www.adr.gov.cn/download/Rmenu.htm
这个菜单还有个好处,不会被<select>标签遮挡哦!~~
一般div不会有这个效果