MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey

这篇翻译不完整。请帮忙从英语翻译这篇文章

全局属性 itemprop ,用于向一个元素中添加属性。每一个HTML元素都可以指定一个itemprop属性,一个itemprop属性由name-value对组成。每一个键值对称为一个属性,一个元素可以有一个或者多个属性。属性值可以是一个string或者一个URL,并且可以和大部分元素进行组合,包括<audio>, <embed>, <iframe>, <img>, <link>, <object>, <source><track>, 和 <video>

例子

下面的例子展示了一组标记有itemprop属性的源代码,后面的表格展示了结果数据。

HTML

<div itemscope itemtype ="http://schema.org/Movie">
  <h1 itemprop="name">Avatar</h1>
  <span>Director:
    <span itemprop="director">James Cameron</span>
    (born August 16, 1954)</span>
  <span itemprop="genre">Science fiction</span>
  <a href="../movies/avatar-theatrical-trailer.html"
    itemprop="trailer">Trailer</a>
</div>

结果数据

  条目
itemprop name itemprop value
itemprop name Avatar
itemprop director James Cameron
itemprop genre Science fiction
itemprop trailer ../movies/avatar-theatrical-trailer.html

属性

属性拥有的值可能同时是字符串或者链接。当一个字符串值是一个URL的时候,它被用 <a> 及它的属性值 href<img> 及它的属性值 src 、或者其它元素被链接到或嵌入外部的资源的来表述。

Three properties with values that are strings

<div itemscope>
 <p>My name is
   <span itemprop="name">Neil</span>.</p>
 <p>My band is called
   <span itemprop="band">Four Parts Water</span>.</p>
 <p>I am
   <span itemprop="nationality">British</span>.</p>
</div>

One property, "image", whose value is a URL

<div itemscope>
 <img itemprop="image"
   src="google-logo.png" alt="Google">
</div>

当一个字符串值不能令人通俗易懂的时候(e.g.,一个长串的数字和字母),它能被用data元素的value属性表示,用所给元素内容的更易懂的版本(它不是结构化数据的一部分-请看下面的例子)。

An item with a property whose value is a product ID

ID是对人不友好的,所以产品的名字是用的人所能看懂的文字而不是ID。

<h1 itemscope>
 <data itemprop="product-id"
   value="9678AOU879">The Instigator 2000</data>
</h1>

对于数字数据,meter 元素及它的 value 属性值能够被使用。

A meter element

<div itemscope itemtype="http://schema.org/Product">
 <span itemprop="name">Panasonic White
   60L Refrigerator</span>
 <img src="panasonic-fridge-60l-white.jpg" alt="">
  <div itemprop="aggregateRating"
       itemscope
       itemtype="http://schema.org/AggregateRating">
   <meter itemprop="ratingValue"
     min=0 value=3.5 max=5>Rated 3.5/5</meter>
   (based on <span
     itemprop="reviewCount">11</span>
     customer reviews)
  </div>
</div>

相似的,对于日期时间相关的数据,time 元素和他的 datetime 属性值能够被使用。

An item with one property, "birthday", whose value is a date

<div itemscope>
 I was born on <time
   itemprop="birthday"
   datetime="2009-05-10">May 10th 2009</time>.
</div>

通过把元素上的 itemscope 属性中声明属性,属性也可以是一个组 name-values 对。每个值既可以是一个字符串又可以是一组 name-values 对(i.e. 一个实体)。

An outer item representing a person, and an inner one representing a band

<div itemscope>
 <p>Name:
   <span itemprop="name">Amanda</span></p>
 <p>Band:
   <span itemprop="band" itemscope>
     <span itemprop="name">Jazz Band</span>
     (<span itemprop="size">12</span>
     players)</span></p>
</div>

上面的外层标签有两个属性,“name” 和 “band”。“name” 的值是 “Amanda”, “band” 的值是一个在它右侧的标签决定的,它有两个属性,“name” 和 “size”。乐队的 “name” 的值是 “Jazz Band”,“size” 的值是 “12”。这个例子的外层标签是顶级微数据标签。不是其他标签的标签被称为顶级微数据标签。

All the properties separated from their items

This example is the same as the previous one, but all the properties are separated from their items

<div itemscope id="amanda" itemref="a b"></div>
<p id="a">Name:
  <span itemprop="name">Amanda</span></p>
<div id="b"
  itemprop="band"
  itemscope itemref="c"></div>
<div id="c">
 <p>Band:
   <span itemprop="name">Jazz Band</span></p>
 <p>Size:
   <span itemprop="size">12</span> players</p>
</div>

This gives the same result as the previous example. The first item has two properties, "name", set to "Amanda", and "band", set to another item. That second item has two further properties, "name", set to "Jazz Band", and "size", set to "12".

An item can have multiple properties with the same name and different values.

Ice cream with two flavors

<div itemscope>
 <p>Flavors in my favorite ice cream:</p>
 <ul>
  <li itemprop="flavor">Lemon sorbet</li>
  <li itemprop="flavor">Apricot sorbet</li>
 </ul>
</div>

This results in an item with two properties, both with the name "flavor" and having the values "Lemon sorbet" and "Apricot sorbet".

An element introducing a property can also introduce multiple properties at once, to avoid duplication when some of the properties have the same value.

An item with two properties, "favorite-color" and "favorite-fruit", both set to the value "orange"

<div itemscope>
 <span
  itemprop="favorite-color
    favorite-fruit">orange</span>
</div>

Note: There is no relationship between the microdata and the content of the document where the microdata is marked up.

Same structured data marked up in two different ways

There is no semantic difference between the following two examples

<figure>
 <img src="castle.jpeg">
 <figcaption><span
   itemscope><span
   itemprop="name">The Castle</span></span>
     (1986)</figcaption>
</figure>
<span itemscope><meta
  itemprop="name"
  content="The Castle"></span>
<figure>
 <img src="castle.jpeg">
 <figcaption>The Castle
  (1986)</figcaption>
</figure>

Both have a figure with a caption, and both, completely unrelated to the figure, have an item with a name-value pair with the name "name" and the value "The Castle". The only difference is that if the user drags the figcaption out of the document, the item will be included in the drag-and-drop data. The image associated with the item won't be included.

Names and values

A property is an unordered set of unique tokens that are case-sensitive and represent the name-value pairs. The property value must have at least one token. In the example below, each data cell is a token.

Names examples

  Item
itemprop name itemprop value
itemprop country Ireland
itemprop Option 2
itemprop https://www.flickr.com/photos/nlireland/6992065114/ Ring of Kerry
itemprop img https://www.flickr.com/photos/nlireland/6992065114/
itemprop website flickr
itemprop (token) (token)

Tokens are either strings or URL's. An item is called a typed item if it is a URL. Otherwise, it is a string. Strings cannot contain a period or a colon (see below).

  1. If the item is a typed item it must be either:
    1. A defined property name, or
    2. A valid URL, which refers to the vocabulary definition, or
    3. A valid URL that is used as a proprietary item property name (i.e. one not defined in a public specification), or
  2. If the item is not a typed item it must be:
    1. A string that contains no "." (U+002E FULL STOP) characters and no ":" characters (U+003A COLON) and is used as a proprietary item property name (again, one not defined in a public specification).

Note: the rules above disallow ":" characters in non-URL values because otherwise they could not be distinguished from URLs. Values with "." characters are reserved for future extensions. Space characters are disallowed because otherwise the values would be parsed as multiple tokens.

Values

The property value of a name-value pair is as given for the first matching case in the following list:

  • If the element has an itemscope attribute
    • The value is the item created by the element.
  • If the element is a meta element
    • The value is the value of the element's content attribute
  • If the element is an audio, embed, iframe, img, source, track, or video element
    • The value is the resulting URL string that results from parsing the value of the element's src attribute relative to the node document (part of the Microdata DOM API) of the element at the time the attribute is set
  • If the element is an a, area, or link element
    • The value is the resulting URL string that results from parsing the value of the element's href attribute relative to the node document of the element at the time the attribute is set
  • If the element is an object element
    • The value is the resulting URL string that results from parsing the value of the element's data attribute relative to the node document of the element at the time the attribute is set
  • If the element is a data element
    • The value is the value of the element's value attribute
  • If the element is a meter element
    • The value is the value of the element's value attribute
  • If the element is a time element
    • The value is the element's datetime value

Otherwise

  • The value is the element's textContent.

If a property's value is a URL, the property must be specified using a URL property element. The URL property elements are the a, area, audio, embed, iframe, img, link, object, source, track, and video elements.

Name order

Names are unordered relative to each other, but if a particular name has multiple values, they do have a relative order.

In the following example, the "a" property has the values "1" and "2", in that order, but whether the "a" property comes before the "b" property or not is not important

<div itemscope>
 <p itemprop="a">1</p>
 <p itemprop="a">2</p>
 <p itemprop="b">test</p>
</div>

The following is equivalent

<div itemscope>
 <p itemprop="b">test</p>
 <p itemprop="a">1</p>
 <p itemprop="a">2</p>
</div>

As is the following

<div itemscope>
 <p itemprop="a">1</p>
 <p itemprop="b">test</p>
 <p itemprop="a">2</p>
</div>

And the following

<div id="x">
 <p itemprop="a">1</p>
</div>
<div itemscope itemref="x">
 <p itemprop="b">test</p>
 <p itemprop="a">2</p>
</div>

Other examples

HTML

<dl itemscope
  itemtype="http://vocab.example.net/book"
  itemid="urn:isbn:0-330-34032-8">
 <dt>Title
   <dd
    itemprop="title">The Reality Dysfunction 
 <dt>Author
   <dd
     itemprop="author">Peter F. Hamilton 
 <dt>Publication date 
 <dd><time
   itemprop="pubdate"
   datetime="1996-01-26">26 January 1996</time>
</dl>

Structured data

itemscope itemtype: itemid http://vocab.example.net/book: urn:isbn:0-330-34032-8
itemprop title The Reality Dysfunction
itemprop author Peter F. Hamilton
itemprop pubdate 1996-01-26

Result

Specifications

Specification Status Comment
itemprop   WG Note - No longer being actively developed

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also

文档标签和贡献者

 此页面的贡献者: MZI, bestdream
 最后编辑者: MZI,