html - 使用 HTML5 微数据时, 'itemscope' 和 'itemtype' 是否应始终用于同一元素?

标签 html syntax microdata

我试图理解存在两个属性背后的原因,而不是仅仅让包含“itemtype”的元素成为包装项目范围的元素。

在一个元素上具有“itemtype”属性而在其他元素上具有“itemscope”属性是否有效?像这样:

<section itemtype="http://data-vocabulary.org/Person">
    <div itemscope>
        <span itemprop="name">Alonso Torres</span>
    </div>
</section>

如果这种情况无效,那么为什么存在 'itemscope' 属性呢?为什么规范没有提出让持有“itemtype”属性的元素成为设置范围的元素的想法。这对我来说很有意义。

最佳答案

你是对的,itemscope 属性似乎是多余的。其他人在 W3C 的 HTML 邮件列表中指出了这一点:http://lists.w3.org/Archives/Public/public-html-bugzilla/2011Jan/0517.html

答案(http://lists.w3.org/Archives/Public/public-html-bugzilla/2011Jan/0523.html)是:

The HTML spec editor did user-testing of the feature earlier, and if I recall correctly, several of the test subjects found it much easier if there was an explicit indicator of the container, rather than it being implicit due to the type.

换句话说,属性有一个明确的定义比多个隐含的定义更好。不确定我是否同意,但这是官方观点。

关于html - 使用 HTML5 微数据时, 'itemscope' 和 'itemtype' 是否应始终用于同一元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5124020/

相关文章:

html - 如何使我的自定义复选框可访问?

ruby - 什么可能的歧义导致此 Ruby 代码抛出 SyntaxError?

schema.org - 为什么 Google 测试工具使用 "id"属性来生成微数据项的 URL?

javascript - react : "Warning: Unknown DOM property itemscope. Did you mean itemScope?"

reactjs - 如何在 React+Typescript 中使用微数据?

jquery - 如何关闭弹出窗口

html - 文本区域中标签文本的自动换行

html - 将两个相邻的 div 与左向文本水平对齐

c# - 无法将 MyType<T> 转换为 MyType<object>

c++ - 无法在类中前向声明类