熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Javascript >> 正文

一個簡單的javascript菜單

2022-06-13   來源: Javascript 

  <!DOCTYPE HTML PUBLIC //WC//DTD HTML Transitional//EN>
<html>
<head>
<title>AgetimeMenu Demo</title>
<meta httpequiv=ContentType content=text/html; charset=gb>
<style>
agetime_bar{
 position:absolute;top:px;left:px;height:px;width:%;border:px outset;backgroundcolor:RGB();zindex:;
}
agetime_barItem{
 width:px;height:px;border:px solid RGB();textalign:left;paddingleft:px;
 background:RGB();color:#;fontsize:pt;
}
agetime_barItemDown{
 width:px;height:px;border:px inset RGB();textalign:left;paddingleft:px;
 background:#FFF;color:#;fontsize:pt;
}
agetime_barItemHover{
 width:px;height:px;border: outset;textalign:left;paddingleft:px;
 background:#FFF;color:#;fontsize:pt;
}
agetime_pad{
 cursor:default;fontsize:pt;width:%;
}
agetime_padItem{
 width:%;height:px;border:px solid RGB();textalign:left;paddingleft:px;
 background:RGB();color:#;fontsize:pt;
}
agetime_padItemFalse{
 paddingleft:px;fontsize:pt; color:#;
}
agetime_padItemFalseHover{
 paddingleft:px;fontsize:pt; color:#;backgroundcolor:#;
}
agetime_padItemHover{
 width:%;height:px;textalign:left;paddingleft:px;
 backgroundcolor:#;color:#FFFFFF;fontsize:pt;
}
agetime_padItemDown{
 width:%;height:px;textalign:left;paddingleft:px;border:px inset;
 backgroundcolor:#CC;color:#FFFFFF;fontsize:pt;
}
agetime_hr{
 border:px inset;
}
agetime_board{
 backgroundcolor:RGB();border:px outset;
}
</style>
</head>
<body>
<script language=javascript>
var menu = agetimeMenu(agetime
 [
  [
  [文件nullnulltrue打開文件] //顯示文字方法命令狀態狀欄顯示文字
  [打開nullnullfalse打開文件]
  []
  [你好jsalert(Hello)true一聲問候]
  [新窗口ABCabout:blanktrue彈出ABC窗口]
  [空白nullabout:blanktrue在當前窗口顯示空白頁]
  ]
  [
  [編輯nullnullfalse打開文件]
  [撤消nullnulltrue打開文件]
  [重做nullnulltrue打開文件]
  ]
  [
  [文件jsalert(無子菜單)true打開文件]
  ]
 ]
);
//方法為js命令則為javascript語句為非js值時命令則是一個URL而打開這個URL的目標位置則是方法所指定的窗口;
//[你好jsalert(Hello)true一聲問候];
//顯示文字為是按鈕是一個分隔符;

  function agetimeMenu(idarray){
 var menu=this;
 menupad=null;   //裝載各個子菜單
 menubarItems=[];  //菜單條的各位按鈕
 menupads=[];   //每個子菜單為一個table存放於menupad上;
 menuselectedIndex=; //菜單條選中按鈕的索引值
 menuboard=null;  //子菜單面板

  //建立菜單條
 thiscrtMenuBar=function(){
  var len=arraylength;
  menubar = documentbodyappendChild(documentcreateElement(div));
  menubarclassName=id+_bar;
  for(var i=;i<len;i++){
  menubarItems[i]=menuaddMenuBarItem(array[i][]i);
  menuaddMenuPad(array[i]i);
  }
 }

  //子菜單
 thisaddMenuPad=function(aryindex){
  var len=arylength;
  var pad=menucrtElement(tablemenupad);
  padcellSpacing=; padcellPadding=;
  padclassName=id+_pad;
  padstyledisplay=none;
  for(var i=;i<len;i++){
  var Row=padinsertRow(i);
  menuaddMenuPadItem(ary[i]Row);
  }
  menupads[index]=pad;
 }

  //各子菜單按鈕
 thisaddMenuPadItem=function(aryRow){
  var Cell=RowinsertCell();
  if(ary[]!=){
   CellinnerText=ary[];
   if(ary[]){ //有效狀態;
   CellclassName=id+_padItem;
   Cellonmouseover=function(){
    CellclassName=id+_padItemHover;
    windowstatus=ary[];
   }
   Cellonmouseout=function(){
    CellclassName=id+_padItem;
    windowstatus=;
   }
   Cellonmousedown=function(){ CellclassName=id+_padItemDown; }
   Cellonmouseup=function(){
    CellclassName=id+_padItemHover;
    menuhideMenu();
    menuexecute(ary);
   }
   }
   else{ //按鈕無效;
   CellclassName=id+_padItemFalse;
   Cellonmouseover=function(){
    CellclassName=id+_padItemFalseHover;
    windowstatus=ary[];
   }
   Cellonmouseout=function(){
    CellclassName=id+_padItemFalse;
    windowstatus=;
   }
   }
  }
  else{
   var hr=menucrtElement(hrCell);
   hrclassName=id+_hr;
  }
  Cellonclick=function(){
   eventcancelBubble=true;
  }
 }

  //菜單條的按鈕
 thisaddMenuBarItem=function(aryindex){
  var item=menucrtElement(buttonmenubar);
  itemvalue=ary[];
  itemdisabled=!ary[];
  itemclassName=id+_barItem;
  itemonmouseover=function(){
  if(menuselectedIndex==){
   itemclassName=id+_barItemHover;
  }
  else{
   menubarItems[selectedIndex]className=id+_barItem;
   itemclassName=id+_barItemDown;
   menushowMenu(index);
  }
  windowstatus=ary[];
  }
  itemonmouseout=function(){
  if(menuselectedIndex==) itemclassName=id+_barItem;
  windowstatus=;
  }
  itemonclick=function(){
  eventcancelBubble=true;
  if(menuselectedIndex==){
   itemclassName=id+_barItemDown;
   menushowMenu(index);
  }
  else{
   menuhideMenu();
   itemclassName=id+_barItemHover;
  }
  menuexecute(ary);
  itemblur();
  }
  return item;
 }

  //顯示子菜單
 thisshowMenu=function(index){
  if(menuselectedIndex!=) menupads[selectedIndex]styledisplay=none;
  menuboardstylepixelLeft=menubarItems[index]offsetLeft+;
  //menuboardstylepixelHeight=;
  if(menupads[index]rowslength>) menuboardstyledisplay=;
  else menuboardstyledisplay=none;
  menupads[index]styledisplay=;
  menuselectedIndex=index;
 }
  //隱藏子菜單
 thishideMenu=function(){
  if(menuselectedIndex==) return;
  menubarItems[menuselectedIndex]className=id+_barItem;
  menupads[selectedIndex]styledisplay=none;
  menuselectedIndex=;
  menuboardstyledisplay=none;
 }

  //執行菜單命令;
 thisexecute=function(ary){
  if(ary[]==null) return;
  if(ary[]==js) { eval(ary[]); menuhideMenu(); }
  else if(ary[]==null || ary[]toLowerCase==_self) locationhref=ary[];
  else{ var x=windowopen(ary[]ary[]); xfocus(); }
 }

  //建立子菜單的顯示面板
 thiscrtMenuBoard=function(){
  documentwrite(
  <div id=+id+_board style=position:absolute;width:px;height:px;left:px;top:px;backgroundcolor:#;zindex:;display:none;>+
   <div style=position:absolute;width:%;height:%;left:px;top:px;>+
   <iframe id=+id+_frame name=+id+_frame width=% height=% frameborder= scrolling=no></iframe>+
   </div>+
   <div id=+id+_pad style=position:absolute;width:%;height:%;left:px;top:px;></div>+
  </div>
  );
  menuboard=documentgetElementById(id+_board);
  menupad=documentgetElementById(id+_pad);
  menupadclassName=id+_board;
  menupadonselectstart=function(){ return false;}
 }

  //增加對像的一個子元素
 thiscrtElement=function(elp){
  return pappendChild(documentcreateElement(el));
 }

  //安裝菜單;
 thissetup=function(){
  menucrtMenuBoard();
  menucrtMenuBar();
  documentattachEvent(onclickmenuhideMenu);
 }

  menusetup();
}
</script>
</body>
</html>


From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/25407.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.