js 下拉级联菜单

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
<script language="javascript">

var Spry;
if(!Spry)
{
 Spry = {};
}
if(!Spry.Widget)
{
 Spry.Widget = {};
}

Spry.Widget.MenuBar = function(element, opts)
{
 this.init(element, opts);
};

Spry.Widget.MenuBar.prototype.init = function(element, opts)
{
 this.element = this.getElement(element);

 // represents the current (sub)menu we are operating on
 this.currMenu = null;

 var isie = (typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE');
 if(typeof document.getElementById == 'undefined' || (navigator.vendor == 'Apple Computer, Inc.' && typeof window.XMLHttpRequest == 'undefined') || (isie && typeof document.uniqueID == 'undefined'))
 {
  // bail on older unsupported browsers
  return;
 }

 // load hover images now
 if(opts)
 {
  for(var k in opts)
  {
   var rollover = new Image;
   rollover.src = opts[k];
  }
 }

 if(this.element)
 {
  this.currMenu = this.element;
  var items = this.element.getElementsByTagName('li');
  for(var i=0; i<items.length; i++)
  {
   this.initialize(items[i], element, isie);
   if(isie)
   {
    this.addClassName(items[i], "MenuBarItemIE");
    items[i].style.position = "static";
   }
  }
  if(isie)
  {
   if(this.hasClassName(this.element, "MenuBarVertical"))
   {
    this.element.style.position = "relative";
   }
   var linkitems = this.element.getElementsByTagName('a');
   for(var i=0; i<linkitems.length; i++)
   {
    linkitems[i].style.position = "relative";
   }
  }
 }
};

Spry.Widget.MenuBar.prototype.getElement = function(ele)
{
 if (ele && typeof ele == "string")
  return document.getElementById(ele);
 return ele;
};

Spry.Widget.MenuBar.prototype.hasClassName = function(ele, className)
{
 if (!ele || !className || !ele.className || ele.className.search(new RegExp("\b" + className + "\b")) == -1)
 {
  return false;
 }
 return true;
};

Spry.Widget.MenuBar.prototype.addClassName = function(ele, className)
{
 if (!ele || !className || this.hasClassName(ele, className))
  return;
 ele.className += (ele.className ? " " : "") + className;
};

Spry.Widget.MenuBar.prototype.removeClassName = function(ele, className)
{
 if (!ele || !className || !this.hasClassName(ele, className))
  return;
 ele.className = ele.className.replace(new RegExp("\s*\b" + className + "\b", "g"), "");
};

// addEventListener for Menu Bar
// attach an event to a tag without creating obtrusive HTML code
Spry.Widget.MenuBar.prototype.addEventListener = function(element, eventType, handler, capture)
{
 try
 {
  if (element.addEventListener)
  {
   element.addEventListener(eventType, handler, capture);
  }
  else if (element.attachEvent)
  {
   element.attachEvent('on' + eventType, handler);
  }
 }
 catch (e) {}
};

// createIframeLayer for Menu Bar
// creates an IFRAME underneath a menu so that it will show above form controls and ActiveX
Spry.Widget.MenuBar.prototype.createIframeLayer = function(menu)
{
 var layer = document.createElement('iframe');
 layer.tabIndex = '-1';
 layer.src = 'javascript:false;';
 menu.parentNode.appendChild(layer);
 
 layer.style.left = menu.offsetLeft + 'px';
 layer.style.top = menu.offsetTop + 'px';
 layer.style.width = menu.offsetWidth + 'px';
 layer.style.height = menu.offsetHeight + 'px';
};

// removeIframeLayer for Menu Bar
// removes an IFRAME underneath a menu to reveal any form controls and ActiveX
Spry.Widget.MenuBar.prototype.removeIframeLayer =  function(menu)
{
 var layers = menu.parentNode.getElementsByTagName('iframe');
 while(layers.length > 0)
 {
  layers[0].parentNode.removeChild(layers[0]);
 }
};

// clearMenus for Menu Bar
// root is the top level unordered list (<ul> tag)
Spry.Widget.MenuBar.prototype.clearMenus = function(root)
{
 var menus = root.getElementsByTagName('ul');
 for(var i=0; i<menus.length; i++)
 {
  this.hideSubmenu(menus[i]);
 }
 this.removeClassName(this.element, "MenuBarActive");
};

// bubbledTextEvent for Menu Bar
// identify bubbled up text events in Safari so we can ignore them
Spry.Widget.MenuBar.prototype.bubbledTextEvent = function()
{
 return (navigator.vendor == 'Apple Computer, Inc.' && (event.target == event.relatedTarget.parentNode || (event.eventPhase == 3 && event.target.parentNode == event.relatedTarget)));
};

// showSubmenu for Menu Bar
// set the proper CSS class on this menu to show it
Spry.Widget.MenuBar.prototype.showSubmenu = function(menu)
{
 if(this.currMenu)
 {
  this.clearMenus(this.currMenu);
  this.currMenu = null;
 }
 
 if(menu)
 {
  this.addClassName(menu, "MenuBarSubmenuVisible");
  if(typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE')
  {
   if(!this.hasClassName(this.element, "MenuBarHorizontal") || menu.parentNode.parentNode != this.element)
   {
    menu.style.top = menu.parentNode.offsetTop + 'px';
   }
  }
  if(typeof document.uniqueID != "undefined")
  {
   this.createIframeLayer(menu);
  }
 }
 this.addClassName(this.element, "MenuBarActive");
};

// hideSubmenu for Menu Bar
// remove the proper CSS class on this menu to hide it
Spry.Widget.MenuBar.prototype.hideSubmenu = function(menu)
{
 if(menu)
 {
  this.removeClassName(menu, "MenuBarSubmenuVisible");
  if(typeof document.all != 'undefined' && typeof window.opera == 'undefined' && navigator.vendor != 'KDE')
  {
   menu.style.top = '';
   menu.style.left = '';
  }
  this.removeIframeLayer(menu);
 }
};

// initialize for Menu Bar
// create event listeners for the Menu Bar widget so we can properly
// show and hide submenus
Spry.Widget.MenuBar.prototype.initialize = function(listitem, element, isie)
{
 var opentime, closetime;
 var link = listitem.getElementsByTagName('a')[0];
 var submenus = listitem.getElementsByTagName('ul');
 var menu = (submenus.length > 0 ? submenus[0] : null);

 var hasSubMenu = false;
 if(menu)
 {
  this.addClassName(link, "MenuBarItemSubmenu");
  hasSubMenu = true;
 }

 if(!isie)
 {
  // define a simple function that comes standard in IE to determine
  // if a node is within another node
  listitem.contains = function(testNode)
  {
   // this refers to the list item
   if(testNode == null)
   {
    return false;
   }
   if(testNode == this)
   {
    return true;
   }
   else
   {
    return this.contains(testNode.parentNode);
   }
  };
 }
 
 // need to save this for scope further down
 var self = this;

 this.addEventListener(listitem, 'mouseover', function(e)
 {
  if(self.bubbledTextEvent())
  {
   // ignore bubbled text events
   return;
  }
  clearTimeout(closetime);
  if(self.currMenu == listitem)
  {
   self.currMenu = null;
  }
  // show menu highlighting
  self.addClassName(link, hasSubMenu ? "MenuBarItemSubmenuHover" : "MenuBarItemHover");
  if(menu && !self.hasClassName(menu, "MenuBarSubmenuVisible"))
  {
   opentime = window.setTimeout(function(){self.showSubmenu(menu);}, 250);
  }
 }, false);

 this.addEventListener(listitem, 'mouseout', function(e)
 {
  if(self.bubbledTextEvent())
  {
   // ignore bubbled text events
   return;
  }

  var related = (typeof e.relatedTarget != 'undefined' ? e.relatedTarget : e.toElement);
  if(!listitem.contains(related))
  {
   clearTimeout(opentime);
   self.currMenu = listitem;

   // remove menu highlighting
   self.removeClassName(link, hasSubMenu ? "MenuBarItemSubmenuHover" : "MenuBarItemHover");
   if(menu)
   {
    closetime = window.setTimeout(function(){self.hideSubmenu(menu);}, 600);
   }
  }
 }, false);
};

</script>
<style>
@charset "UTF-8";

/* SpryMenuBarVertical.css - Revision: Spry Preview Release 1.4 */

/* Copyright (c) 2006. Adobe Systems Incorporated. All rights reserved. */

/*******************************************************************************

 LAYOUT INFORMATION: describes box model, positioning, z-order

 *******************************************************************************/

/* The outermost container of the Menu Bar, a fixed width box with no margin or padding */
ul.MenuBarVertical
{
 margin: 0;
 padding: 0;
 list-style-type: none;
 font-size: 100%;
 cursor: default;
 width: 8em;
}
/* Set the active Menu Bar with this class, currently setting z-index to accomodate IE rendering bug: http://therealcrisp.xs4all.nl/meuk/IE-zindexbug.html */
ul.MenuBarActive
{
 z-index: 1000;
}
/* Menu item containers, position children relative to this container and are same fixed width as parent */
ul.MenuBarVertical li
{
 margin: 0;
 padding: 0;
 list-style-type: none;
 font-size: 100%;
 position: relative;
 text-align: left;
 cursor: pointer;
 width: 8em;
}
/* Submenus should appear slightly overlapping to the right (95%) and up (-5%) with a higher z-index, but they are initially off the left side of the screen (-1000em) */
ul.MenuBarVertical ul
{
 margin: -5% 0 0 95%;
 padding: 0;
 list-style-type: none;
 font-size: 100%;
 position: absolute;
 z-index: 1020;
 cursor: default;
 width: 8.2em;
 left: -1000em;
 top: 0;
}
/* Submenu that is showing with class designation MenuBarSubmenuVisible, we set left to 0 so it comes onto the screen */
ul.MenuBarVertical ul.MenuBarSubmenuVisible
{
 left: 0;
}
/* Menu item containers are same fixed width as parent */
ul.MenuBarVertical ul li
{
 width: 8.2em;
}

/*******************************************************************************

 DESIGN INFORMATION: describes color scheme, borders, fonts

 *******************************************************************************/

/* Outermost menu container has borders on all sides */
ul.MenuBarVertical
{
 border: 1px solid #CCC;
}
/* Submenu containers have borders on all sides */
ul.MenuBarVertical ul
{
 border: 1px solid #CCC;
}
/* Menu items are a light gray block with padding and no text decoration */
ul.MenuBarVertical a
{
 display: block;
 cursor: pointer;
 background-color: #EEE;
 padding: 0.5em 0.75em;
 color: #333;
 text-decoration: none;
}
/* Menu items that have mouse over or focus have a blue background and white text */
ul.MenuBarVertical a:hover, ul.MenuBarVertical a:focus
{
 background-color: #33C;
 color: #FFF;
}
/* Menu items that are open with submenus are set to MenuBarItemHover with a blue background and white text */
ul.MenuBarVertical a.MenuBarItemHover, ul.MenuBarVertical a.MenuBarItemSubmenuHover, ul.MenuBarVertical a.MenuBarSubmenuVisible
{
 background-color: #33C;
 color: #FFF;
}

/*******************************************************************************

 SUBMENU INDICATION: styles if there is a submenu under a given menu item

 *******************************************************************************/

/* Menu items that have a submenu have the class designation MenuBarItemSubmenu and are set to use a background image positioned on the far left (95%) and centered vertically (50%) */
ul.MenuBarVertical a.MenuBarItemSubmenu
{
 background-image: url(SpryMenuBarRight.gif);
 background-repeat: no-repeat;
 background-position: 95% 50%;
}

/* Menu items that are open with submenus have the class designation MenuBarItemSubmenuHover and are set to use a "hover" background image positioned on the far left (95%) and centered vertically (50%) */
ul.MenuBarVertical a.MenuBarItemSubmenuHover
{
 background-image: url(SpryMenuBarRightHover.gif);
 background-repeat: no-repeat;
 background-position: 95% 50%;
}

/*******************************************************************************

 BROWSER HACKS: the hacks below should not be changed unless you are an expert

 *******************************************************************************/

/* HACK FOR IE: to make sure the sub menus show above form controls, we underlay each submenu with an iframe */
ul.MenuBarVertical iframe
{
 position: absolute;
 z-index: 1010;
}
/* HACK FOR IE: to stabilize appearance of menu items; the slash in float is to keep IE 5.0 from parsing */
@media screen, projection
{
 ul.MenuBarVertical li.MenuBarItemIE
 {
  display: inline;
  float: left;
  background: #FFF;
 }
}

</style>
</head>

<body>
<ul id="MenuBar1" class="MenuBarVertical">
  <li><a class="MenuBarItemSubmenu" href="#">项目 1</a>
      <ul>
        <li><a href="#">项目 1.1</a></li>
        <li><a href="#">项目 1.2</a></li>
        <li><a href="#">项目 1.3</a></li>
      </ul>
  </li>
  <li><a href="#">项目 2</a></li>
  <li><a class="MenuBarItemSubmenu" href="#">项目 3</a>
      <ul>
        <li><a class="MenuBarItemSubmenu" href="#">项目 3.1</a>
            <ul>
              <li><a href="#">项目 3.1.1</a></li>
              <li><a href="#">项目 3.1.2</a></li>
            </ul>
        </li>
        <li><a href="#">项目 3.2</a></li>
        <li><a href="#">项目 3.3</a></li>
      </ul>
  </li>
  <li><a href="#">项目 4</a></li>
</ul>
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script>
</body>
</html>

时间: 2024-09-29 22:25:20

js 下拉级联菜单的相关文章

JS下拉缓冲菜单示例代码_javascript技巧

复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> body,html

js下拉展开菜单

提示:您可以先修改部分代码再运行 孤雁儿 世人作梅词,下笔便俗.予试作一篇,乃知前言不妄耳. 藤床纸帐朝眠起, 说不尽.无佳思. 沈香烟断玉炉寒, 伴我情怀如水. 笛声三弄, 梅心惊破, 多少春情意. 小风疏雨萧萧地, 又催下.千行泪. 吹箫人去玉楼空, 肠断与谁同倚? 一枝折得, 人间天上, 没个人堪寄. 作者:李清照展开来源 :中国诗辞网 提示:您可以先修改部分代码再运行

js 下拉折叠菜单代码

','')"> 神华神东电力有限责任公司2×12MW煤粉湿冷机组.1×16500KVA电石生产线.2×12500KVA电石生产线及5×3万吨/年焦化生产线等拆除工程范围系指与神华神东电力有限责任公司2×12MW煤粉湿冷机组.1×16500KVA电石生产线.2×12500KVA电石生产线及5×3万吨/年焦化生产线等相关联的设备及建构物.范围内所有的设备及建构物的基础.范围内的地上地下所有管线及范围内室外沟道拆除,但不包括所有拆除区域内的树木,并保证拆除后,地面平整,无沟道.无建筑垃圾等.上述

js下拉导航菜单代码

产品介绍 产品一 产品一 产品一 产品一 产品一 产品一 服务介绍 服务二 服务二 服务二 服务二服务二 服务二服务二服务二 服务二 成功案例 案例三 案例 案例三案例三 案例三案例三案例三 关于我们 我们四 我们四 我们四 我们四111 在线演示 演示 演示 演示 演示演示演示 演示演示演示 演示演示 演示演示演示 演示演示演示演示演示 联系我们 联系联系联系联系联系 联系联系联系 联系 联系联系 联系联系 联系联系联系 联系联系联系

js下拉导航菜单

<script Language="JavaScript">  var h;  var w;  var l;  var t;  var topMar = 3;  var leftMar = -10;  var space = 2;  var isvisible;  var MENU_SHADOW_COLOR='#999999';  var global = window.document  global.fo_currentMenu = null  global.fo_sh

js下拉框二级关联菜单效果代码具体实现

这篇文章介绍了js下拉框二级关联菜单效果代码具体实现,有需要的朋友可以参考一下   复制代码 代码如下:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml&quo

js自动查找select下拉的菜单并选择

 这篇文章主要介绍了js自动查找select下拉的菜单并选择(示例代码)需要的朋友可以过来参考下,希望对大家有所帮助  代码如下: function find_select(name) {  var select = document.getElementsByName(name);  var find_str = document.getElementById('to_find_str').value;  if(select)  {   select = select[0];   var ch

30多个CSS和JS下拉菜单资源

导航菜单是网站设计中最重要的 因素之一.网络开发人员可以使用CSS创建方便用户的横向或纵向导航菜单, 而JavaScript则使人们有可能创造更多的互动,更多的响应和更灵活的导航到任何网站.Noupe在这篇文章里面提出了25个以上(横向和纵向)多 层次的下拉菜单,包括使用了JavaScript和CSS ,你可以将这些示例和教程用你的未来网站设计计划.帕兰照常为你翻译, 你也可以查看帕兰映像之前发表的一些关于菜单应用的文章: IzzyMenu: 在线创建DHTML/CSS菜单 9款CSS菜单生成器

ext-Ext Js 下拉菜单显示不正常

问题描述 Ext Js 下拉菜单显示不正常 求Ext大神帮忙