0
我有2個div的,我有toggleClass打開後,如下:jQuery的toggleclass 2周的div - 打開一個與關閉其他
<!-- links to open div's -->
<div class="sort-filter">
<div class="sort">
<a href="#" class="sort"><em class="fa fa-sort"></em> SORT</a>
</div>
<div class="filter">
<a href="#" class="filter"><em class="fa fa-filter"></em> FILTER</a>
</div>
</div>
<!-- divs to toggle open/close -->
<div class="search-options clearfix" style="display: none;">
content options here
</div>
<div class="search-filters clearfix" style="display: none;">
content filters here
</div>
我用下面的jQuery來切換div的:
<script type="text/javascript">
$(function ($) {
var search_options = $('.search-options');
$('a.sort').click(function() {
$(this).toggleClass('show');
search_options.slideToggle(400);
if (!$(this).hasClass('show')) {
$('a.filter').removeClass('show'); // hide the other one
}
return false;
});
var search_filters = $('.search-filters');
$('a.filter').click(function() {
$(this).toggleClass('show');
search_filters.slideToggle(400);
if (!$(this).hasClass('show')) {
$('a.sort').removeClass('show'); // hide the other one
}
return false;
});
});
</script>
但我的邏輯被搞砸了。
我想要一個鏈接關閉其他div如果打開&反之亦然。
任何想法的?
喜歡的東西[本小提琴(http://jsfiddle.net/y4sftnsz/1/)用'如果( $(本).hasClass( '秀'))'? – Regent