简体   繁体   English

多级下拉菜单不起作用

[英]Multi-level drop down menu not working

I have a drop down menu that works on the first level. 我有一个下拉菜单可以在第一级使用。 But I can't get the second level of the menu to show. 但是我无法显示菜单的第二级。 Thanks for help. 感谢帮助。

javascript javascript

<script type="text/javascript">
$(document).ready(function () {
$('#nav li').hover(
function () {
//show submenu
$('ul', this).css({zIndex:90}).fadeIn(150);
},
function () {
//hide submenu
$('ul', this).fadeOut(150);

}
);

HTML 的HTML

<input type="hidden" name="arav" /><ul id="nav">
<li> <a href="index2.html">Home</a>
</li>
<li> <a href="personnel.html">Who We Are</a>
</li>
<li> <a href="#">Neurologic Condition</a>
<ul>
<li><a href="sci.html">SCI</a></li>
<li><a href="tbi.html">TBI</a></li>
<li><a href="stroke.html">Other</a></li>
</ul>
</li>
<li> <a href="">Education</a>
<ul>
<li><a href="healthed.html">Health Education</a></li>
<li><a href="#"> Materials</a>
<ul>Videos
<li>Videos</li>
<li>Presentation</li>
<li>Movies</li>
</ul>

</li>

<li><a href="sciinfosheets.html">SCI Info Sheets</a></li>
</ul>
</li>
<li> <a href="stroke.html">Resources</a>
<ul>
<li><a href="statelevel.html">State Level</a></li>
<li><a href="nationallevel.html">National Level</a></li>
<li><a href="resourcesbycoutny2.html">Community Level</a></li>
</ul>
</li>

<li> <a href="research.html">Research</a></li>

<li> <a href="contactus.html">Contact Us</a>
</li>
</ul>

CSS 的CSS

#nav {
margin:0;
padding:0;
list-style:none;
behavior: url(border-radius.htc);

}

/*LI display inline */
#nav li {
float:left;
display:block;
width:7em;
background:#0063dc;
position:relative;
z-index:500;
margin:0 1px;
}

/*parent menu*/
#nav li a {
display:block;
padding:5px 5px 5px 5px;
font-weight:700;
height:38px;
text-decoration:none;
color:#696969;
text-align:center;
color:#ffeecc;
}

#nav li a:hover
{
color:#eeeeee;
}

/* style for default selected value */ #nav a.selected {
color:#6699FF;
}
/* submenu */ #nav ul
{
position:absolute;
left:0;
display:none;
margin:0 0 0 -1px;
padding:0;
list-style:none;
}

#nav ul li
{
width:7em;
float:left;
overflow:hidden;
border-top:1px solid #eeeeee;
}

#nav ul a
{
display:block;
height:32px;
padding: 7px 4px;
color:white;
}

#nav ul a:hover
{
text-decoration:none;
}

It might be just a problem with your html: 这可能只是您的html的问题:

<li><a href="#"> Materials</a>
<ul>Videos                 // this is not valid
<li>Videos</li>

is not valid html. 无效的html。

Do you have an example online? 您在网上有例子吗?

Edit: I have added an example in jsfiddle . 编辑:我在jsfiddle中添加了一个示例。

One of the first problems I encountered, is your use of #nav ul li { overflow: hidden } . 我遇到的第一个问题是您对#nav ul li { overflow: hidden } That means that everything that overflows your li (like the sub-sub menus) will be hidden. 这意味着所有会溢出li (如子子菜单)都将被隐藏。 Apart from that you will have to add some positioning for the lowest level menus. 除此之外,您还必须为最低级别的菜单添加一些位置。

It still needs some tidying but the problem with the tertiary menu not showing was that #nav ul li had overflow:hidden set which no matter what hid the tertiary menu. 它仍然需要进行一些整理,但是三级菜单没有显示的问题是#nav ul li overflow:hidden设置,无论隐藏三级菜单是什么。 Removing that fixes the problem. 删除可以解决问题。 I also tweaked the JS a little in the demo below too. 我也在下面的演示中对JS进行了一些调整。

Demo: jsfiddle.net/Marcel/kydTs 演示: jsfiddle.net/Marcel/kydTs

apart from the HTML error pointed out above, the CSS is not complete either, you've got all child lists positioned to appear flush left.. so they are actually just on top of each other plus you've got child li's set to overflow: hidden; 除了上面指出的HTML错误之外,CSS也不完整,您已经将所有子列表定位为向左对齐..因此它们实际上彼此重叠,并且您将子li设置为overflow: hidden; so their children are also hidden 所以他们的孩子也被隐藏了

the the jQuery is slightly wrong, it's going to drop all the children li s soon as the first list is hovered on, I presume you just want the appear when it's immediate parent is hovered on? jQuery略有错误,将第一个列表悬停在其上会立即删除所有子项li ,我想您只是想将其直接父悬停在其出现时出现?

amended CSS: 修改后的CSS:

#nav {
margin:0;
padding:0;
list-style:none;
behavior: url(border-radius.htc);
}

#nav {width: 100%;}
#nav ul, #nav li {width: 7em;}

/*LI display inline */
#nav li {
float:left;
background:#0063dc;
position:relative;
z-index:500;
margin:0 1px;
text-align:center;
}

/*parent menu*/
#nav li a {
display:block;
padding:5px 5px 5px 5px;
font-weight:700;
height:38px;
text-decoration:none;
color:#ffeecc;
}

#nav li a:hover {
color:#eeeeee;
}

/* style for default selected value */ 
#nav a.selected {
color:#6699FF;
}
/* submenu */ 
#nav ul {
position:absolute;
display:none;
margin:0 0 0 -1px;
padding:0;
list-style:none;
}

#nav ul {left: 0;}
#nav ul ul {left: 100%; top: 0;}

#nav ul li {
/*overflow:hidden;*/
border-top:1px solid #eeeeee;
}

#nav ul li:hover {position: relative;}

#nav ul a {
display:block;
height:32px;
padding: 7px 4px;
color:white;
}

#nav ul a:hover {
text-decoration:none;
}

an amended script: 修改后的脚本:

<script type="text/javascript">
$(document).ready(function() {

    $("#nav li").hover(
        function () {
        $(this).children("ul").fadeIn(250);
        },function(){
        $(this).children("ul").fadeOut(250);
    });//hover

});// document ready
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM