对于常见问题解答,我尝试将HTML,WAI-ARIA和Microdata(使用Schema.org)结合起来,但SDTT验证只显示了Question
,而不是Answer
。
<section class="accordion" role="tablist" aria-live="polite">
<details>
<summary aria-controls="panel0" role="tab" itemprop="mainEntity" itemscope itemtype="https://schema.org/Question">
<p temprop="name">How to beat the boss...spoiler alert !</p>
<meta itemprop="answerCount" content="1"/>
</summary>
<div itemprop="acceptedAnswer" itemscope itemtype="https://schema.org/Answer">
<p aria-labelledby="tab0" role="tabpanel" itemprop="text"> Just aim to the red spots near his eyes Keep shooting at these spots until the eyes open, then hit quickly both eyes with your laser beam.</p>
</div>
</details>
</section>
SDTT显示Answer
,但它与Question
处于同一水平(因此它们没有关联)。
这样做的原因是你没有将Answer
添加到Question
,而是添加到父项(在你的代码段中缺少)。
具有div
属性的acceptedAnswer
需要成为Question
元素的子元素。如果你的标记不可能(因为Answer
不应该是summary
元素的一部分),你可以使用Microdata的itemref
属性:
<details>
<summary aria-controls="panel0" role="tab" itemprop="mainEntity" itemscope itemtype="https://schema.org/Question" itemref="answer">
<p temprop="name">How to beat the boss...spoiler alert !</p>
<meta itemprop="answerCount" content="1"/>
</summary>
<div id="answer" itemprop="acceptedAnswer" itemscope itemtype="https://schema.org/Answer">
<p aria-labelledby="tab0" role="tabpanel" itemprop="text"> Just aim to the red spots near his eyes Keep shooting at these spots until the eyes open, then hit quickly both eyes with your laser beam.</p>
</div>
</details>
(我将itemref="answer"
添加到Question
,并将id="answer"
添加到Answer
。)