[原创]修改了StedyMenu为js版的可动态增加,如图,并赋上JS代码

类别:网站制作 点击:0 评论:0 推荐:

1.用的是Stedysoft的2k3Menu里的图片,css,及3个htc:2k3MenuBar.htc,2k3Menu.htc,2k3MenuRoot.htc
2.需要修改的地方就是 将 2k3MenuRoot.htc 里的 <PUBLIC:property name="menu" value /> 修改为<PUBLIC:property name="subMenu" value />,然后将给htc有关menu的都改为subMenu;
3.我修改的js脚本如下:
var oMenubar;
//Nodes.Add("R",4,"P3","Item0");
//Add(null,0,"R","Root");
/*
 功能:添加菜单项
 参数:
  parentItem: 上级节点的ID,如果为null,则为第一菜单项
  level   : 菜单级别。
    0:第一条
    1:最后条
    2:下一条
    3:上一条
    4:子菜单
  item   : 菜单id
  itemName  : 菜单名称
example:
   插入第一个菜单 addItem(null,0,"item1","我是第一个菜单");  
*/
function addItem(parentItem,level,item,itemName,itemTitle,itemClick,imageSrc){
 //添加MenuRoot
 if ((parentItem=="null")||(level==0)){
  //添加一个MenuBar
  oMenubar = document.all.item("_MenuBar").firstChild.firstChild;
  var oItem=oMenubar.insertCell(oMenubar.cells.length - 1);
  with (oItem){
   id=item;
   Height="25";
   noWrap=true;
   className="2k3MenuRoot";
   //title=itemTitle;   
   innerHTML="<div class=\"2k3MenuRootCaption\" >"+itemName+"</div>";
  }
 } 
 //添加子菜单
 if ((parentItem!="null")||(parentItem!="")){
  if (level==4){
   var oSubMenuItem="_SubMenu_"+parentItem;
   
   var oParentMenu=document.all.item(parentItem);
   //如果找不到父菜单
   if (oParentMenu==null){
    return;
   }
   var oSubMenu=document.all.item(oSubMenuItem);

   if (oSubMenu==null){
    createMenu(oSubMenuItem);
    oSubMenu=document.all.item(oSubMenuItem);
    //return;
    document.all.item(parentItem).subMenu=oSubMenuItem;

   }
   //不是MenuRoot,则添加箭头
   if (oParentMenu.className!="2k3MenuRoot"){    
    oParentMenu.cells(oParentMenu.cells.length - 2).className="2k3MenuMore";
   }
   //添加一行分割线
   if (itemName=="-"){
    var oRow=oSubMenu.tBodies(0).insertRow();
    with (oRow){
     className="2k3MenuSeperator";
     var oCell=insertCell();
     oCell.className="2k3MenuImage";
     oCell.colSpan="2";
     
     oCell=insertCell();
     oCell.className="2k3MenuCaption";
     oCell.colSpan="3";
     oCell.innerHTML="<IMG>";
    } 
   }else if(itemName!=null){
    var oRow=oSubMenu.tBodies(0).insertRow();
    with (oRow){
     className="2k3MenuItem";
     id=item;
     title=itemTitle;
     var oCell=insertCell();
     oCell.clsssName="2k3MenuVerticalSpacerLeft";
     
     oCell=insertCell();
     oCell.className="2k3MenuImage";
     oCell.innerHTML="<img src="+imageSrc+" width=\"16\" height=\"16\">";
     
     oCell=insertCell();
     oCell.className="2k3MenuCaption";
     oCell.innerText=itemName;     
     
     oCell=insertCell();
     oCell.className="2k3MenuNoMore";
     oCell.innerText="4";
     
     oCell=insertCell();
     oCell.className="2k3MenuVerticalSpacerRight";

    }    
   }
     
  }  
  
 } 
}         


function createMenubar(){
 var htmlstr="<table class=\"2k3MenuBar\" id=\"_MenuBar\" cellspacing=0 cellpadding=0 width=100% height=20>";
 htmlstr+="  <tr>";
 htmlstr+="   <td class=2k3MenuBarHandle></td>";
 //htmlstr+="   <td class=\"2k3MenuRoot\" id=\"_mnuRoot1\" ><div class=\"2k3MenuRootCaption\">File</div></td>";
 htmlstr+="   <td width=100%></td>";
 htmlstr+="  </tr>";
 htmlstr+="</table>";
 document.write(htmlstr);
}

function createMenu(item){
 var htmlstr;
 htmlstr="<table class=\"2k3Menu\" id="+item+" cellspacing=\"0\" cellpadding=\"0\">";
 htmlstr+=" <thead><tr><td colspan=\"5\"><div class=\"2k3MenuRootConnector\"></div></td></tr></thead>";
 htmlstr+=" <tbody>";
 htmlstr+=" </tbody>";
 htmlstr+=" <tfoot><tr><td colspan=\"5\"></td></tr></tfoot>";
 htmlstr+="</table>";
 document.write(htmlstr);

//document.onclick=function{
// if event.
//}

function doClick(){
 var el=window.event.srcElement;

  if (el.parentElement.className=="2k3MenuImage"){
   el=el.parentElement.parentElement;
  }else if ((el.className=="2k3MenuVerticalSpacerLeft")|(el.className=="2k3MenuCaption")|(el.className=="2k3MenuNoMore")|(el.className=="2k3MenuVerticalSpacerRight")){
 el=el.parentElement;
  }else{
   return
  }
  //alert(el.className);
  if ((el.className=="2k3MenuItem")|(el.className=="2k3MenuItemOver")){
   alert(el.id);
  }
}

5.举例应用。
<Script language="javascript">
createMenubar();
addItem(null,0,"m_System","系统","系统设置",null,null);
addItem("m_System",4,"m_SkinSetting","界面设置","根据自己的喜好来配置界面","demo()",null);
addItem("m_SkinSetting",4,"m_SkinSetting1","界面设置1","根据自己的喜好来配置界面","demo()",null);
addItem("m_SkinSetting",4,"m_SkinSetting2","界面设置2","根据自己的喜好来配置界面","demo()",null);
addItem("m_SkinSetting",4,"m_SkinSetting3","界面设置3","根据自己的喜好来配置界面","demo()",null);
addItem("m_System",4,"m_ChangePwd","修改密码","修改用户的登陆密码","demo()",null);
addItem("m_System",4,"-","-","-","demo()",null);
addItem("m_System",4,"m_ReLogin","重新登陆","更换其它用户名登录","demo()",null);
addItem("m_System",4,"m_Exit","退出","退出系统","demo()",null);
addItem("m_Exit",4,"m_Exit01","退出子菜单","退出系统","demo()",null);
addItem("m_Exit",4,"m_Exit02","退出子菜单1","退出系统","demo()",null);
</script>

4.效果如图:[img]http://blog.csdn.net/images/blog_csdn_net/juwuyi/59408/t_StedyMenu_JoeCom.gif[/img]

本文地址:http://com.8s8s.com/it/it31317.htm