【发布时间】:2018-06-14 04:27:18
【问题描述】:
我正在设计一个类似手风琴的布局,并且希望在单击 div 时切换我显示的箭头图标。我可以切换 div 的内容。我想对箭头图标做同样的事情。
这是我迄今为止尝试过的。
$(document).ready(function() {
$(this).on("click", ".koh-faq-question", function() {
$(this).parent().find(".koh-faq-answer").toggle();
});
});
.koh-faqs-page-title {
font-family: Nexa W01 Heavy;
font-size: 30px;
color: #04202E;
font-weight: 700;
}
.koh-faq-question-span {
font-family: Helvetica Neue LT Pro Roman !important;
font-size: 16px !important;
color: #000 !important;
font-weight: 700 !important;
display: inline-block;
}
.koh-faq-answer {
font-family: Helvetica Neue LT Pro Roman;
color: #000;
font-weight: 400;
display: none;
}
.icon {
font-size: 10px;
padding-right: 5px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="koh-tab-content">
<div class="koh-tab-content-body">
<div class="koh-faq">
<div class="koh-faq-question">
<i class="fa fa-chevron-right" aria-hidden="true"></i>
<span class="koh-faq-question-span"> Test Question 1 </span>
</div>
<div class="koh-faq-answer">
Test Answer 1
</div>
</div>
</div>
</div>
我希望在单击问题时将右侧图标切换为向下图标。当我再次单击时,它应该切换回左侧图标。由于它是一个常见问题页面,我将有多个问题和答案。所以我想为每个人做。
【问题讨论】:
-
只需删除类
fa-chevron-right并将类fa-chevron-down添加到元素<i class="fa"></i>- 当然是点击。
标签: javascript jquery html css