1
Copyright © 2018-2026 东莞市中谊精密仪器有限公司 版权所有
ICP备案号:粤ICP备2022118559号
// FAQ 解析 + 结构化数据自动注入 document.addEventListener('DOMContentLoaded', function() { var faqBlock = document.querySelector('.faq-raw-data'); if (!faqBlock) return; var items = faqBlock.querySelectorAll('.faq-qa-item'); if (items.length === 0) return; var faqs = []; items.forEach(function(item) { var q = item.getAttribute('data-q'); var a = item.getAttribute('data-a'); if (q && a) faqs.push({ q: q, a: a }); }); if (faqs.length === 0) return; // --- 渲染FAQ HTML --- var html = '

常见问题

'; faqs.forEach(function(f, i) { html += '
'; html += '
Q' + (i+1) + '' + f.q + '
'; html += '
A' + f.a + '
'; html += '
'; }); html += '
'; faqBlock.outerHTML = html; // --- 注入JSON-LD结构化数据 --- var script = document.createElement('script'); script.type = 'application/ld+json'; script.textContent = JSON.stringify({ "@context": "https://schema.org", "@type": "FAQPage", "mainEntity": faqs.map(function(f) { return { "@type": "Question", "name": f.q, "acceptedAnswer": { "@type": "Answer", "text": f.a } }; }) }); document.head.appendChild(script); // --- 点击展开/收起 --- document.querySelectorAll('.faq-q').forEach(function(q) { q.addEventListener('click', function() { var answer = this.nextElementSibling; answer.style.display = answer.style.display === 'block' ? '' : 'block'; this.querySelector('.faq-arrow').textContent = answer.style.display === 'block' ? '▲' : '▼'; }); }); });
Processed in 0.061700 Second , 80 querys.