如何在点击" HEADER"之后切换辅助导航链接。按钮(在"这应该切换ul链接"),并且一次只能切换一个。当用户单击该按钮时,它应该关闭其级别的任何其他子空间链接,只允许一次打开一个。它也应该能够关闭,而不会触发另一个打开。
<div class="inner">
<button data-target="#data-nav-0" data-toggle="collapse" data-state="show" class="list-header major no-style"> <span>HEADER</span> </button>
<div class="col-wrapper collapse in" id="data-nav-0" style="display: block;">
<div class="column">
<ul class="list-unstyled">
<li class="list-header mobile"><a href="#" class="link">link</a></li>
<li class="list-header desktop"><a href="#">head</a></li>
<li class="mobile chevron-right" data-target="#data-inner-0-0" data-toggle="collapse" data-state="hide">
<button class="no-style">This should toggle the ul links</button>
</li>
<ul class="inner collapse" id="data-inner-0-0">
<li><a href="#" class="link">link</a></li>
<li><a href="#" class="link">link</a></li>
<li><a href="#" class="link">link</a></li>
<li><a href="#" class="link">link</a></li>
</ul>
</ul>
</div>
<div class="column">
<ul class="list-unstyled">
<li class="list-header desktop"><a href="#">Link</a></li>
<li class="mobile chevron-right" data-target="#data-inner-0-1" data-toggle="collapse" data-state="hide">
<button class="no-style">This should toggle the ul links</button>
</li>
<ul class="inner collapse" id="data-inner-0-0">
<li><a href="#" class="link">link</a></li>
<li><a href="#" class="link">link</a></li>
<li><a href="#" class="link">link</a></li>
<li><a href="#" class="link">link</a></li>
</ul>
</ul>
</ul>
</div>
</div>
</div>
的jQuery
$('.list-header').next('div').toggle();
$('.list-header').click(function() {
$('.list-header').next('div').slideUp();
$(this).next('div').toggle();
return false;
});
$('.mobile').next('div').toggle();
$('.mobile').click(function() {
$('.mobile').next('div').slideUp();
$(this).next('div').toggle();
return false;
});
JSFIDDLE:https://jsfiddle.net/jdkwcpva/
答案 0 :(得分:1)
此代码解决了您的问题:
$('.mobile').next('ul').toggle(); // <-- .next('ul') instead of .next('div')
$('.mobile').click(function() {
$('.mobile').next('ul').slideUp(); // <-- same
$(this).next('ul').toggle(); // <-- same
return false;
});
的 DEMO 强>