简体   繁体   English

jQuery FAQ功能切换不起作用,因为我想要它

[英]Jquery FAQ function toggling not working as I want it to

PSL Answered it for me, thanks man! PSL为我回答了,谢谢! :) :)

So I got this code: 所以我得到了这段代码:

$(document).ready(function () {

$('.faqs .answer').hide();
$('.faqs .question').click(function(){
    $('.faqs .answer').slideUp('normal');
    $(this).next().slideDown('normal');
}); 

}); });

And it's working fine, but the problem is that when I click the same FAQ (the FAQ that you just opened) it will toggle it, so it will go up and down, offcourse that's what my code says to do so, is there any way I can stop this from happening? 而且它工作正常,但是问题是,当我单击相同的FAQ(您刚刚打开的FAQ)时,它将切换它,因此它将上下移动,这是我的代码所说的话,那么我可以阻止这种情况发生的方法? I am using the same Class names, which simply is question and answer. 我使用相同的类名称,这只是问题和答案。 So what I want it to do is that it should only go up whenever you click the slided down div. 因此,我要执行的操作是仅当您单击向下滑动的div时,它才应该上升。

<div class="faqs">
    <div class="question">Can you help me?</div>
    <div class="answer">I hope so</div>
</div>

Thanks already, Jordy 已经谢谢你了,乔迪

You could use not to exclude the current elements target, which still sliding it down: 您可以使用not排除当前元素目标,但仍将其向下滑动:

$('.faqs .question').click(function(){
    var $target = $(this).next();
    $('.faqs .answer:visible').not($target.slideDown('normal')).slideUp('normal');
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM