大家看看我的修改的一个关于右键菜单的程序,特别是,meizz(梅花雨)

apboy 2002-07-25 06:45:58
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<style>
.skin0{
position:absolute;
width:150px;
border:2px solid black;
background-color:menu;
font-family:Verdana;
line-height:20px;
cursor:default;
visibility:hidden;
}

.skin1{
cursor: default;
font: menutext;
position: absolute;
width: 150px;
background-color: menu;
border: 1 solid buttonface;
visibility:hidden;
border: 2 outset buttonhighlight;
}

.menuitems{
padding-left:15px;
padding-right:10px;
}
</style>
<script language=Javascript>
function down(tid,gid){
if(event.button==2){
ie5menu.className="skin1";
ie5menu.style.left=document.body.scrollLeft+event.clientX;
ie5menu.style.top=document.body.scrollTop+event.clientY;
ie5menu.style.visibility="visible";
}
}

//set the skin of the menu (0 or 1, with 1 rendering a default Windows menu like skin)
var menuskin=1

//set this variable to 1 if you wish the URLs of the highlighted menu to be displayed in the status bar
var display_url=0

function highlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor="highlight"
event.srcElement.style.color="white"
if (display_url==1)
window.status=event.srcElement.url
}
}

function lowlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor=""
event.srcElement.style.color="black"
window.status=''
}
}

function jumptoie5(){
if (event.srcElement.className=="menuitems"){
if (event.srcElement.getAttribute("target")!=null)
window.open(event.srcElement.url,event.srcElement.getAttribute("target"))
else
window.location=event.srcElement.url
}
}
</SCRIPT>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<p>
<p>

<p>
<p>
<a href="http://www.sina.com.cn" onmousedown="javascript:down('id1','002')">连接一</a><br>
<a href="http://www.163.com" onmousedown="javascript:down('id1','002')">连接二</a>
</p>
</p>
</p>
</p>
<div id="ie5menu" class="skin0" onMouseover="highlightie5()" onMouseout="lowlightie5()" onClick="jumptoie5()">
<div class="menuitems" url="addGroup.htm" target="main">添加子组</div>
<div class="menuitems" url="delGroup.jsp" target="main">修改该组</div>
<div class="menuitems" url="#">删除该组</div>
</div>
</body>
</html>
...全文
58 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
apboy 2002-07-26
  • 打赏
  • 举报
回复
谢谢meizz(梅花雨)!不过我可能还有问题,先结贴再说吧
meizz 2002-07-25
  • 打赏
  • 举报
回复
<!-- 时间较紧,改得仓促! -->
<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>
apboy 2002-07-25
  • 打赏
  • 举报
回复
谢谢!
孟子E章 2002-07-25
  • 打赏
  • 举报
回复
http://go6.163.com/colorweb/xml/xmlcontextmenu.html
apboy 2002-07-25
  • 打赏
  • 举报
回复
上面例子我有两个问题:
1。在击右键菜单时,window的菜单也出现,怎么禁止?
2。现在我想把down(tid,gid)中参数传到添加子组、删除改组和修改组等这些连接中,问怎么传递参数?急盼解

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧