我有這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>
單擊向子元素添加一個類並將鼠標懸停在外如果類存在,則不要上移 –