' +
' ' +
'
';
});
container.innerHTML = html;
// 绑定点击事件
var items = container.querySelectorAll('.faq-item');
items.forEach(function(item) {
var q = item.querySelector('.faq-question');
q.addEventListener('click', function() {
item.classList.toggle('open');
});
q.addEventListener('keydown', function(e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
q.click();
}
});
});
}
// 渲染所有分组
for (var key in faqData) {
if (faqData.hasOwnProperty(key)) {
var groupId = 'group-' + key;
renderFAQ(groupId, faqData[key]);
}
}
// 额外渲染「全部」—— 合并所有问题(含新增)
var allContainer = document.getElementById('group-all');
if (allContainer) {
var allHtml = '';
var allItems = [];
for (var k in faqData) {
if (faqData.hasOwnProperty(k)) {
faqData[k].questions.forEach(function(q) {
allItems.push(q);
});
}
}
allItems.forEach(function(item) {
allHtml +=
'' + item.a + '
' +
' ' +
'
';
});
allContainer.innerHTML = allHtml;
var allItemsEl = allContainer.querySelectorAll('.faq-item');
allItemsEl.forEach(function(item) {
var q = item.querySelector('.faq-question');
q.addEventListener('click', function() {
item.classList.toggle('open');
});
q.addEventListener('keydown', function(e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
q.click();
}
});
});
}
// ============================================================
// Tab 切换
// ============================================================
var tabs = document.querySelectorAll('.faq-tab');
var groups = document.querySelectorAll('.faq-group');
tabs.forEach(function(tab) {
tab.addEventListener('click', function() {
tabs.forEach(function(t) { t.classList.remove('active'); });
tab.classList.add('active');
var targetId = tab.getAttribute('data-target');
groups.forEach(function(g) {
if (g.id === targetId) {
g.classList.add('active');
} else {
g.classList.remove('active');
}
});
var container = document.querySelector('.faq-container');
if (container) {
container.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});
});
})();
' +
' ' + item.q + '' +
' ' +
'
' +
' ' + item.a + '
