我真的坚持我的代码,它工作正常,除了一件事,我需要关闭所有打开的 div,当我单击其他 div 打开时,这是我的代码:
function readFaq() {
$('.find-faq-inner h3').prepend('<span id="spanfaq" class="faq-open"></span>');
$('.find-faq-inner h3').each(function () {
var tis = $(this), state = false;
var answer = tis.next('div').hide().css('height', 'auto').slideUp();
tis.click(function () {
state = !state;
answer.slideToggle(state);
tis.toggleClass('active', state);
if (state == true) {
tis.find('#spanfaq').removeClass('faq-open');
tis.find('#spanfaq').addClass('faq-close');
}
else {
tis.find('#spanfaq').removeClass('faq-close');
tis.find('#spanfaq').addClass('faq-open');
}
});
});
}
<div class="find-faq-inner">
<div class="text">
<h3>FAQ1</h3>
<div>
text of faq
</div>
</div>
</div>
任何想法都会有所帮助,谢谢