JS高手请进来救我!!!

ren2008 2008-01-07 10:27:32

<SCRIPT language=JScript>
<!--
function RightMenu()
{
this.AddItem=AddItem;
this.GetMenu=GetMenu;
this.I_OnMouseOver=I_OnMouseOver;

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='140' border='0' cellspacing='0'>\n"; //width参数可以设置菜单宽度
HTMLstr += "<tr><td height='200' width='100%' valign='bottom' bgcolor='#000000' onclick=window.event.cancelBubble=true; class=info>版权<br>:恩优科技<br>:<br>请勿侵权\n";
HTMLstr += "</td><td height='200' width='100%' style='padding: 1' valign='bottom'>\n";
HTMLstr += "<table width='100%' border='0' cellspacing='0'>\n";
HTMLstr += "<!-- Insert A Extend Menu or Item On Here For E_rbpm -->\n";
HTMLstr += "</table></td></tr></table>\n";
HTMLstr += "</div>\n";
HTMLstr += "<!-- Insert A Extend_Menu Area on Here For E_rbpm -->";
HTMLstr += "\n";
HTMLstr += "<!-- PopMenu Ends -->\n";
}

var menu = new RightMenu();//AddItem参数(id,img,wh,name,parent,location)
menu.AddItem("update","start_update","1","查看酒店<font class=w2kfont>(<u>V</u>)</font>","rbpm",document.cookie);
menu.AddItem("sperator","","","","rbpm",null);
menu.AddItem("program","start_pro","2","   团体预定<font class=w2kfont>(<u>P</u>)</font>","rbpm",document.cookie);
menu.AddItem("doc","start_doc","3","   散客入住<font class=w2kfont>(<u>D</u>)</font>","rbpm",document.cookie);
menu.AddItem("fav","start_fav","4","  团体入住<font class=w2kfont>(<u>A</u>)</font>","rbpm","aa");
menu.AddItem("sperator","","","","rbpm",null);
menu.AddItem("setting","start_set","a"," 酒店特色<font class=w2kfont>(<u>S</u>)</font>","rbpm","aa");
menu.AddItem("find","start_find","v","  最新活动<font class=w2kfont>(<u>F</u>)","rbpm","aa");
menu.AddItem("sperator","","","","rbpm",null);
menu.AddItem("refresh","start_help","7","   刷新<font class=w2kfont>(<u>H</u>)</font>","rbpm",null);
menu.AddItem("back","start_logoff","+","  后退<font class=w2kfont>(<u>L</u>)</font>","rbpm",null);
menu.AddItem("exit","start_shut","x","  退出<font class=w2kfont>(<u>U</u>)</font>","rbpm",null);
document.writeln(menu.GetMenu());

function Display()//右键显示
{
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 RM_Method(str)//右键时的方法
{
document.cookie=str;
//RightMenu();
Display();
}

function AddItem(id,img,wh,name,parent,location) //("update","start_update","4","<font class=w2kfont>查看酒店</font>","rbpm","<%=strid %>");
{
var TempStr = "";
var ItemStr = "<!-- ITEM : I_"+id+" -->";
if(id == "sperator") //判断是下划线
{
TempStr += ItemStr+"\n";
TempStr += "<tr class='out' onclick='window.event.cancelBubble=true;' onmouseup='window.event.cancelBubble=true;'><td colspan='2' height='1'><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 +="<font face='Wingdings' style='font-size:18px'>"+wh+"</font> "+ name+" "; //图标样式:<font face='Wingdings' style='font-size:18px'>-</font>
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 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.onclick=OnClick; //单击取消菜单

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_help(){
var s_help='<style>body,td{font:menu;padding:2}</style>';
s_help+='<title>帮助</title>';
s_help+='<body bgcolor=menu>';
s_help+='<br> 欢迎光临无忧视窗!本系统和您的Windows系统操作很相似。单击开始,打开开始菜单,双击桌面图标打开相关文件!<span style="color:blue;cursor:hand" onclick=showHelp("windows.chm::/MS-ITS:ntdef.chm::/default.htm")>本机帮助..</span>';
showModalDialog("about:"+s_help+"","","dialogHeight:110px;dialogWidth:210px;help:yes;status:no")}
-->
</SCRIPT>
...全文
74 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ren2008 2008-01-07
  • 打赏
  • 举报
回复

function RightMenu()
{
this.AddItem=AddItem;
this.GetMenu=GetMenu;
this.I_OnMouseOver=I_OnMouseOver;

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='140' border='0' cellspacing='0'>\n"; //width参数可以设置菜单宽度
HTMLstr += "<tr><td height='200' width='100%' valign='bottom' bgcolor='#000000' onclick=window.event.cancelBubble=true; class=info>版权<br>:恩优科技<br>:<br>请勿侵权\n";
HTMLstr += "</td><td height='200' width='100%' style='padding: 1' valign='bottom'>\n";
HTMLstr += "<table width='100%' border='0' cellspacing='0'>\n";
HTMLstr += "<!-- Insert A Extend Menu or Item On Here For E_rbpm -->\n";
HTMLstr += "</table></td></tr></table>\n";
HTMLstr += "</div>\n";
HTMLstr += "<!-- Insert A Extend_Menu Area on Here For E_rbpm -->";
HTMLstr += "\n";
HTMLstr += "<!-- PopMenu Ends -->\n";
}

var menu = new RightMenu();//AddItem参数(id,img,wh,name,parent,location)
menu.AddItem("update","start_update","1","查看酒店<font class=w2kfont>(<u>V</u>)</font>","rbpm",document.cookie);
menu.AddItem("sperator","","","","rbpm",null);
menu.AddItem("program","start_pro","2","   团体预定<font class=w2kfont>(<u>P</u>)</font>","rbpm",document.cookie);
menu.AddItem("doc","start_doc","3","   散客入住<font class=w2kfont>(<u>D</u>)</font>","rbpm",document.cookie);
menu.AddItem("fav","start_fav","4","  团体入住<font class=w2kfont>(<u>A</u>)</font>","rbpm","aa");
menu.AddItem("sperator","","","","rbpm",null);
menu.AddItem("setting","start_set","a"," 酒店特色<font class=w2kfont>(<u>S</u>)</font>","rbpm","aa");
menu.AddItem("find","start_find","v","  最新活动<font class=w2kfont>(<u>F</u>)","rbpm","aa");
menu.AddItem("sperator","","","","rbpm",null);
menu.AddItem("refresh","start_help","7","   刷新<font class=w2kfont>(<u>H</u>)</font>","rbpm",null);
menu.AddItem("back","start_logoff","+","  后退<font class=w2kfont>(<u>L</u>)</font>","rbpm",null);
menu.AddItem("exit","start_shut","x","  退出<font class=w2kfont>(<u>U</u>)</font>","rbpm",null);
document.writeln(menu.GetMenu());


想请问一下高手,能不能把上面两段代码整合在一个函数function Test() 下,方便我后面直接调用这个函数,现在这样子我好像调用不了??
我JS不太熟悉,试着尝试过,但没有成功,哎,希望高手指点下

rotApple 2008-01-07
  • 打赏
  • 举报
回复
可以啊:

把两个RightMenu改成function RightMenu1和function RightMenu2
然后

function Test()
{
RightMenu1();
RightMenu2();
}

哈哈. 你代码太长了, 没啥时间看哦.不好意思. 不知道你是不是这个意思.

87,910

社区成员

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

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