event.srcElement获取节点,event.srcElement.tagName判断是不是a标签,如果是a标签,获取它的href属性,然后用解析获取的字符串,来实现功能。

解决方案 »

  1.   

    这些代码我在我做过的项目里都已经实现,不过当时是做项目,没考虑其它的因素,因此我也就没有在CSDN里发布了。你若是想做这些东东,我可以帮助你:QQ:112889082
      

  2.   

    fantiny(虽然我是菜鸟,不过我是~~非暴力不合作~~的菜鸟)
    你这种想法可以实现,但是可扩展性等不强,且有时候要提供给右键菜单的信息量超出你有链接里带的信息量,你如何解决?所以这里面还是要另外建立一条信息通道,给树节点与右键菜单里互访数据。
      

  3.   

    恩,你说得很对,同意。
    如果信息量大,只要另外写个数据结构来保存。url就只带index查询的参数。
      

  4.   

    <html><head><title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style>
    td     {font-size: 13px}
    .menu1 {cursor: default}
    </style>
    <script language=Javascript>
    var menuclass,menutitle;
    function document.onmouseover(){
        menuclass = window.event.toElement.className;
        menutitle = window.event.toElement.innerText;
        }
    function document.onmousedown(){
      var x = window.event.clientX;
      var y = window.event.clientY;
      var x0=document.body.clientWidth;
      var y0=document.body.clientHeight;    if(event.button==2 && (menutitle=="MenuTitle1" || menutitle=="MenuTitle2")){       
            ie5menu.style.display="";  
            var x1=document.all.ie5menu.clientWidth;
            var y1=document.all.ie5menu.clientHeight;
            ie5menu.style.left = (x0-x-4<x1) ? x-x1-4 : x+2;
            ie5menu.style.top  = (y0-y<y1)   ? y-y1-4 : y;
            }
        if(event.button==1 && menuclass != "menu1") ie5menu.style.display = "none";
    }function jumptoie5(){
      if (event.srcElement.className=="menu1"){
         if (event.srcElement.getAttribute("target")!=null)
            window.open(event.srcElement.url,event.srcElement.getAttribute("target"))
         else
            window.location=event.srcElement.url
         }
      ie5menu.style.display = "none";
      }function mo(tt,st){  
      if (tt=="over"){st.background='highlight';st.color='#FFFFFF';}
      else           {st.background='menu';     st.color='#000000';}
      }
    </SCRIPT>
    </head>
    <body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0  oncontextmenu="window.event.returnValue=false;"
     onkeydown="if(event.keyCode==27)document.all.ie5menu.style.display='none';">
    <br><br><br><br>
    &nbsp; &nbsp; &nbsp; <a href="http://www.sina.com.cn">MenuTitle1</a><br><br>
    &nbsp; &nbsp; &nbsp; <a href="http://www.163.com">MenuTitle2</a><DIV id=ie5menu style="BACKGROUND: menu; border: 2 outset #FFFFFF;z-index: 12; position: absolute; display: none" onclick="jumptoie5()">
    <table border=0 cellspacing=2 cellpadding=1>
    <tr><td noWrap class=menu1 onmouseover=mo("over",this.style) onmouseout=mo("out",this.style) url="addGroup.htm" target="main">&nbsp; Add</td></tr>
    <tr><td noWrap class=menu1 onmouseover=mo("over",this.style) onmouseout=mo("out",this.style) url="delGroup.jsp" target="main">&nbsp; Edit</td></tr>
    <tr><td noWrap class=menu1 onmouseover=mo("over",this.style) onmouseout=mo("out",this.style) url="#">&nbsp; Del</td></tr>
    </table></div></body>
    </html>