鑑於以下html結構,如何使#top-bar-toggle
切換點擊,除非點擊.top-bar-menu-search
或其子女?切換點擊,除了一個元素
<div id="top-bar-toggle">
<div id="top-bar-menu">
<ul class="vertical menu">
<li>
<a href="home_link"><h2>Home Item</h2></a>
</li>
<li>
<a href="other_link"><h2>Other Item</h2></a>
<ul class="nested vertical menu">
<li><a href="nested_link"><h2>Nested Item</h2></a></li>
<li><a href="nested_link"><h2>Nested Item</h2></a></li>
<li><a href="nested_link"><h2>Nested Item</h2></a></li>
</ul>
</li>
<li>
<a href="other_link"><h2>Other Item</h2></a>
<ul class="nested vertical menu">
<li><a href="nested_link"><h2>Nested Item</h2></a></li>
<li><a href="nested_link"><h2>Nested Item</h2></a></li>
<li><a href="nested_link"><h2>Nested Item</h2></a></li>
</ul>
</li>
<li class="top-bar-menu-search">
<form id="searchform" method="get" role="search">
<div class="input-group">
<span class="input-group-label"></span>
<input type="text" placeholder="Search" id="s" name="s" value="" class="input-group-field">
</div>
</form>
</li>
</ul>
</div>
</div>
我想下面的jQuery代碼會工作,但#top-bar-toggle
元素獲得反正切換...
$('#top-bar-toggle').not('.top-bar-menu-search').click(function() {
$(this).fadeToggle();
});
提前感謝!
它只是沒有工作,因爲我需要的'#頂級酒吧toggle'元素來切換當一個又按下外'#頂酒吧menu'。但是,無論如何謝謝你的答案。 –