HTML5 itemscope属性是什么,用通俗易懂的术语做什么?


Answers:


67

[itemscope]属性是一个布尔属性,用于定义元素中包含的元数据的范围。

它在HTML5 Microdata API中定义:

每个HTML元素都可以itemscope指定一个属性。该itemscope属性是布尔属性。

itemscope指定了属性的元素将创建一个新项目,即一组名称/值对。

换句话说,这是将元数据与特定DOM节点相关联的一种方式。

这是通过使用Schema.org API为搜索引擎和社交网络相关联的数据。Google+使用架构来为用户共享的页面提供标题,缩略图和描述。


还应该注意的是[itemscope],当为网页提供元数据时,并且[itemprop]与Facebook的Open Graph协议兼容。可以在一组<meta>元素中为搜索引擎,Facbook和Google+列出相同的元数据,而不必多次列出相同的信息:

<html itemscope itemtype="http://schema.org/WebPage" xmlns:fb="https://www.facebook.com/2008/fbml">
  <head>
    <title>An Example Title</title>
    <meta content="An Example Title" itemprop="name" property="og:title" />
    <meta content="Lorem ipsum dolor sit amet" itemprop="description" name="description" property="og:description" />
    <meta content="http://www.example.com/image.jpg" itemprop="image" property="og:image" />
    <meta content="http://www.example.com/permalink" itemprop="url" property="og:url" />
    <link rel="canonical" href="http://www.example.com/permalink" />
  </head>
  <body>
    ...content...
  </body>
</html>

注意,在示例中,[itemscope]已添加到<html>元素。这意味着,任何[itemprop]在属性<head><body>是部分WebPage项目。



34

搜索引擎包括Bing,Google和Yahoo! 现在正在使用itemscope和朋友来识别网页中的语义数据。在schema.org网站上,他们对如何将itemscope与预定义的架构结合使用进行了说明,以改善提供给搜索引擎的数据。

http://schema.org/docs/gs.html

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.