我有这2级导航。如果我点击第二级别,它不应该隐藏,但坚持在那里。在悬停时,第二级显示正确,现在我想要的是,我点击sub 2并移动光标,sub 2应该被选中并停留在那里。坚持二级导航onclick
$(document).ready(function() {
var $nav = $('#top_navigation > ul > li');
$nav.hover(
function() {
\t $('ul', this).stop(true, true).slideDown('fast');
$('a',this).first().css({"background-color":"#ccc", "color":"#000"});
\t },
\t function() {
$('ul', this).slideUp('fast');
$('a',this).first().css({"background-color":"#ccc", "color":"#000"});
\t }
);
});
#top_navigation {
width: 1248px;
margin: 0 auto;
position: relative;
text-transform: uppercase;
font-family: "Rounded Font", sans-serif;
font-size: 13px;
}
#top_navigation ul ul {
display: none;
}
#top_navigation ul {
padding-left: 0;
}
#top_navigation ul li {
margin: 0;
padding: 0;
float: left;
width: 100px;
height: 30px;
line-height: 30px;
font-size: 13px;
list-style: none;
}
#top_navigation ul li a {
\t display: block;
text-align: center;
text-decoration: none;
color: #000;
background-color: #FFF;
}
#top_navigation ul li.selected_menu_item a {
background-color: #ccc;
color: #FFF;
}
#top_navigation ul li a:hover {
background-color: #ccc;
color: #FFF;
}
#top_navigation li li {
height: 30px;
line-height: 30px;
border-top: #ccc 1px solid;
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body bgcolor="black">
<div id="top_navigation">
\t \t <ul>
\t \t \t <li><a href="#">item1</a></li>
\t \t \t <li><a href="#">item2</a>
\t \t \t \t <ul class="submenu">
\t \t \t \t \t <li><a href="#">sub1</a></li>
\t \t \t \t \t <li><a href="#">sub2</a></li>
\t \t \t \t \t <li class="selected_menu_item"><a href="#">sub3</a></li>
\t \t \t \t </ul>
\t \t \t </li>
\t \t </ul>
\t </div>
</body>
</html>
单击向子元素添加一个类并将鼠标悬停在外如果类存在,则不要上移 –