function document.onmouseover()
{
menutitle = window.event.toElement.innerText;
//得到鼠标当前所对应的文字,以便判断是否弹出菜单
}
{
menutitle = window.event.toElement.innerText;
//得到鼠标当前所对应的文字,以便判断是否弹出菜单
}
解决方案 »
- 页面中无线联动下拉框
- jquery ui拖动后保存位置求高人指点
- 一个非常好用的WEB打印控件“四方在线WEB打印控件"
- google maps 示例代码的疑惑
- javascript的加法计算器程序——调试不出来,请高手指教
- 用js写一个函数往FreeTextBox控件里面插入一个框架
- 判断图片大小的JS代码,就剩10分了 大侠帮个忙,给你们跪下了!!
- js 如何将网站上的图片下载到指定本机上?
- 在javascript的循环语句里面再镶嵌循环语句应该怎么写?
- javascript中把数据写入到execl文件中,如何设置自动行高?
- 当我点击一个下拉列表内容,另一个下拉列表的内容会相应改变,应该怎样做?
- 如何用javascript读取源文件!在线等!!!!!!!急
1.
ie5menu_style应该写成:ie5menu.style
2.
两个层的名称重了,而且和一个连接的名称相同,所以在你的函数中是用group得到的是一个数组ie5menu.style是空值。
3.
document.oncontextmenu=showmenuie5(menuName)
document.oncontextmenu=""
这样写是错误的,改:
document.oncontextmenu=function(){showmenuie5(menuName);}
document.oncontextmenu=null;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>右键菜单</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- // RightClickMenu
document.oncontextmenu=function(){return false;};function showmenuie5(menuName){
var ie5menu=eval(menuName)
var rightedge=document.body.clientWidth-event.clientX
var bottomedge=document.body.clientHeight-event.clientY
if (rightedge<ie5menu.offsetWidth)
ie5menu.style.left=document.body.scrollLeft+event.clientX-ie5menu.offsetWidth
else
ie5menu.style.left=document.body.scrollLeft+event.clientX
if (bottomedge<ie5menu.offsetHeight)
ie5menu.style.top=document.body.scrollTop+event.clientY-ie5menu.offsetHeight
else
ie5menu.style.top=document.body.scrollTop+event.clientY
ie5menu.style.visibility="visible"
return false
}
function hidemenuie5(menuName){
var ie5menu=eval(menuName)
ie5menu.style.visibility="hidden"
}
function highlightie5(itemName){
if (event.srcElement.className==itemName){
event.srcElement.style.backgroundColor="highlight"
event.srcElement.style.color="white"
}
}
function lowlightie5(itemName){
if (event.srcElement.className==itemName){
event.srcElement.style.backgroundColor=""
event.srcElement.style.color="black"
}
}
function jumptoie5(itemName){
if (event.srcElement.className==itemName){
if (event.srcElement.url != ''){
if (event.srcElement.getAttribute("target")!=null)
window.open(event.srcElement.url,event.srcElement.getAttribute("target"))
else
window.location=event.srcElement.url
}
}
}
// -->
</SCRIPT>
<STYLE TYPE='text/css'>
.cMenu{
position: absolute;
visibility:hidden;
color:#000000;
width:200px;
border:2px solid #000000;
background-color:#999999;
font-size:14px;
font-weight:normal;
line-height:20px;
cursor:default;
}.menuitems{
padding-left:15px;
padding-right:10px;
}
</STYLE>
</head><body>
<p> <a href="javascript:void();" name="user" id="user" onMouseOver="rightmenu('group1')" onMouseOut="rightmenu_clear();">用户</a></p>
<a href="javascript:void();" name="group" id="group" onMouseOver="rightmenu('group2');" onMouseOut="rightmenu_clear();">组</a>
<p></p>
<RightClick>
<!--[if IE]>
<div id="group1" name="group1" class="cMenu" onMouseover="highlightie5('usermenuitems')" onMouseout="lowlightie5('usermenuitems')" onClick="jumptoie5('usermenuitems')">
<div class="usermenuitems" url="javascript:alert ('usercreate')">创建用户</div>
<div class="usermenuitems" url="javascript:alert ('usermodify')">修改用户</div>
<div class="usermenuitems" url="javascript:alert ('userdel')">删除用户</div>
<![endif]-->
<!--[if IE]>
<div id="group2" name="group2" class="cMenu" onMouseover="highlightie5('groupmenuitems')" onMouseout="lowlightie5('groupmenuitems')" onClick="jumptoie5('groupmenuitems')">
<div class="groupmenuitems" url="javascript:alert ('usercreate')">创建组</div>
<div class="groupmenuitems" url="javascript:alert ('usermodify')">修改组</div>
<div class="groupmenuitems" url="javascript:alert ('userdel')">删除组</div>
<![endif]-->
<script language="JavaScript">
<!--
function rightmenu(menuName){
if (document.all&&window.print){
ie5menu=eval(menuName)
//alert (ie5menu)
ie5menu.className="cMenu"
document.oncontextmenu=function(){showmenuie5(menuName);return false;}
document.body.onclick=function(){hidemenuie5(menuName);}
}
}
function rightmenu_clear(){
document.oncontextmenu=function(){return false;};
document.onclick=null;
}
//-->
</script>
</RightClick>
</body>
</html>
<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=="连接一" || menutitle=="连接二")){
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;
//这种位置设置法的好处在于碰到不够宽的时候菜单会真实window菜单一样移位
}
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';//ESC键隐藏菜单">
<br><br><br><br>
<a href="http://www.sina.com.cn">连接一</a><br><br>
<a href="http://www.163.com">连接二</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"> 添加子组 </td></tr>
<tr><td noWrap class=menu1 onmouseover=mo("over",this.style) onmouseout=mo("out",this.style) url="delGroup.jsp" target="main"> 修改该组</td></tr>
<tr><td noWrap class=menu1 onmouseover=mo("over",this.style) onmouseout=mo("out",this.style) url="#"> 删除该组</td></tr>
</table></div></body>
</html>
再问一个问题:
如果我要动态生成右键菜单怎么办?
如
-------------
用户
用户1
用户2
组
组1
组2
-------------
树图是从数据库中动态生成的,
现在要求,在“用户1”中点右键,需传用户ID到URL中。如url="modify.asp?id=1"或者 "modify.asp?id=2",组也一样。
应该是用innerHTML方法吧,不过我不太熟悉JS和DHTML:(
“传用户ID到URL中”:这样页面就刷新了,干吗还要点右健呢?做个连接不就行了。
如
-------------
用户
用户1
用户2
组
组1
组2
-------------
树图是从数据库中动态生成的,
在任一用户上点击右键,出现“创建用户,修改用户,删除用户”菜单
不同用户的“修改用户”和“删除用户”菜单的URL是不同的,如modify.asp?id=1 or id=2 or id=3,ID号是从数据库是取的用户ID号。
现在的关键是下面这段,我想动态生成,就是指向不同链接时才产生DIV,这样就可将ID值传过去了<!--[if IE]>
<div id="group" name="group" class="cMenu" onMouseover="highlightie5('usermenuitems')" onMouseout="lowlightie5('usermenuitems')" onClick="jumptoie5('usermenuitems')">
<div class="usermenuitems" url="create.asp">创建用户</div>
<div class="usermenuitems" url="modify.asp?id="+id>修改用户</div>
<div class="usermenuitems" url="del.asp?id="+id>删除用户</div>
<![endif]-->
<div class="usermenuitems" url="modify.asp?id=<%=id%>>修改用户</div>其中<%=id%>是asp的变量