របៀបដាក់សំណួរសួរញឹកញាប់ - FAQs
សួស្ដី!បាទ ខានជួបគ្នារៀងយូរដែរហើយ ថ្ងៃនេះខ្ញុំសូមលើកយករបៀបក្នុងការដាក់សំណួរសួរញឹកញាប់ ដែលភាសាអង់គ្លេសហៅថា Frequently Asked Questions (FAQs)។ FAQs នេះដែរជាទូទៅគេប្រើសម្រាប់ដាក់ជាសំណួរចម្លើយអោយបានដឹងពីផលិតផលឬសេវាកម្មផ្សេងៗរបស់ពួកគេទៅដល់អ្នកប្រើប្រាស់។ ១.ចូលទៅកាន់ Theme => Edit HTML រួចចម្លងកូដខាងក្រោមដាក់ពីខាងលើ </head>
<style type="text/css">
#faqs{display:grid;grid-template-columns:1fr;gap:20px}
.faq-item{border:1px solid rgba(155,155,155,0.19);border-radius:3px}
.faq-item h3.faq-question{display:flex;justify-content:space-between;gap:15px;font-size:15px;font-weight:500;cursor:pointer;padding:15px;margin:0;transition:all .17s ease}
.faq-item h3.faq-question::after{content:'+'}
.faq-item.active h3.faq-question::after{content:'-'}
.faq-item h3:hover,.faq-item.active h3{color:#ff0000}
.faq-content{display:none;padding:15px;border-top:1px solid rgba(155,155,155,0.19)}
.faq-content p.faq-answer{margin:0}
</style>២.ចម្លងកូដខាងក្រោមដាក់ពីខាងលើ </body> បន្ទាប់មកចុច Icon Save រួចចាកចេញពីផ្ទាំង Edit HTML <script type="text/javascript">
$('#faqs').each(function () {
let $this = $(this),
renderFaq = "";
faqLists.forEach((faq, index) => {
renderFaq += '<div class="faq-item item-' + (index + 1) + '">';
renderFaq += '<h3 class="faq-question" data-question="' + (index + 1) + '">' + faq.question + '</h3>';
renderFaq += '<div class="faq-content">';
renderFaq += '<p class="faq-answer" data-answer="' + (index + 1) + '">' + faq.answer + '</p>';
renderFaq += '</div></div>';
});
$this.html(renderFaq);
$('.faq-question').on('click', function () {
let $this = $(this).parent(),
$next = $(this).next();
if ($this.hasClass('active')) {
$next.slideUp();
$this.removeClass('active');
} else {
$('.faq-content').slideUp();
$('.faq-item').removeClass('active');
$this.addClass('active');
$next.slideDown();
}
})
});
</script>៣.ចម្លងកូដខាងក្រោមដាក់ក្នុង Blog Page ដោយប្ដូរទៅជា HTML view <div id="faqs"></div>
<script>
let faqLists = [{
question: "១.សំណួរ ទី១",
answer: "ចម្លើយ ទី១"
},
{
question: "២.សំណួរ ទី២",
answer: "ចម្លើយ ទី២"
},
];
</script>៤.កែប្រែ ឫ បន្ថែមព័ត៌មានសំណួរ និង ចម្លើយ ខាងលើរួចចុចពាក្យ Publish ជាការស្រេច៕
Comments
Post a Comment