event.srcElement获取节点,event.srcElement.tagName判断是不是a标签,如果是a标签,获取它的href属性,然后用解析获取的字符串,来实现功能。
解决方案 »
- js如何实现监控input值的改变?
- js如何太动构建一个控件
- 下面这段为什么不起作用?注意描红的地方
- 怎样知道网页中的一张图片所在的位置?
- var d="2005-11-1";如何在这个日期上加上48天?
- Jquery怎样获取网络图片的宽高?
- 提交方式 action="${fn:getLink('co/coCheck.jsp') }" method="post"> <
- 请教一个问题(分不够可以加的)
- 如何处理IE5中调用window.close()会弹出“是否关闭当前窗口”的提示框的问题
- <DIV>元素定位问题?送100分!!!
- 在htc文件的innerHTML里,能用onclick=click()之类的写法吗?
- JS如何实现鼠标划矩形窗格并记录左上角和右下角坐标值?
你这种想法可以实现,但是可扩展性等不强,且有时候要提供给右键菜单的信息量超出你有链接里带的信息量,你如何解决?所以这里面还是要另外建立一条信息通道,给树节点与右键菜单里互访数据。
如果信息量大,只要另外写个数据结构来保存。url就只带index查询的参数。
<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>
<a href="http://www.sina.com.cn">MenuTitle1</a><br><br>
<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"> Add</td></tr>
<tr><td noWrap class=menu1 onmouseover=mo("over",this.style) onmouseout=mo("out",this.style) url="delGroup.jsp" target="main"> Edit</td></tr>
<tr><td noWrap class=menu1 onmouseover=mo("over",this.style) onmouseout=mo("out",this.style) url="#"> Del</td></tr>
</table></div></body>
</html>