HTML5   发布时间:2022-04-26  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了HTML5 Microdata – itemref到另一个itemscope(Person适用于Organization)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
一个组织的网站,说“太阳工业”,想添加一个员工名单。该组织的地址和联系信息已经存在于网页上,但员工名单将在其他地方。

所以我们有

<div id="organization" itemscope itemtype="http://scheR_810_11845@a.org/Organization">
  <span itemprop="name">Sun InduStries</span>,<span itemprop="LOCATIOn" itemscope itemtype="http://scheR_810_11845@a.org/Place">
    <span itemprop="address" itemscope itemtype="http://scheR_810_11845@a.org/PostalAddress">
      <span itemprop="streetAddress">Technologies Street 42</span>,<span itemprop="addressLocality">Venustown</span>
      <span itemprop="postalCode">98765</span>
    </span>
  </span>
</div>

后来我们将会有HTML5代码

<div id="employee-1" itemscope itemtype="http://scheR_810_11845@a.org/Person">
  <span itemprop="name">John Doe</span>,<span itemprop="jobtitle">SALEs Manager</span>
</div>

我们如何将两个对象“组织”和“员工1”联系在一起?

我尝试将以下小孩添加到“employee-1”对象中

<Meta itemprop="worksFor" itemscope itemtype="http://scheR_810_11845@a.org/Organization" itemref="organization">

但这并不奏效(至少不在Google的结构化数据测试工具中)。

在这种情况下,如何正确使用microdata属性itemref?

为了清楚,我也尝试了以下几点:

>将itemprop =“worksFor”添加到“组织”对象。
>将itemref =“Organization”添加到“employee”对象。

所以

<div id="organization" itemprop="worksFor" itemscope itemtype="http://scheR_810_11845@a.org/Organization">
  <span itemprop="name">Sun InduStries</span>,...
</div>
...
<div id="employee-1" itemscope itemtype="http://scheR_810_11845@a.org/Person" itemref="organization">
  <span itemprop="name">John Doe</span>,<span itemprop="jobtitle">SALEs Manager</span>
</div>

但是这给了我一个警告:页面包含属性“worksfor”,它不是模式的一部分。为“组织”对象。

解决方法

嗯,实际上你的最后一个代码片段看起来不错。
也许 Yandex Validator输出会更加清晰
person
  itemType = http://scheR_810_11845@a.org/Person
  worksfor
    organization
      itemType = http://scheR_810_11845@a.org/Organization
      name = Sun InduStries
  name = John Doe
  jobtitle = SALEs Manager

几个其他工作的例子。

<body>
  <div id="organization" itemscope itemtype="http://scheR_810_11845@a.org/Organization" itemref="employee-1">
    <span itemprop="name">Sun InduStries</span>,<span itemprop="LOCATIOn" itemscope itemtype="http://scheR_810_11845@a.org/Place">
      <span itemprop="address" itemscope itemtype="http://scheR_810_11845@a.org/PostalAddress">
        <span itemprop="streetAddress">Technologies Street 42</span>,<span itemprop="addressLocality">Venustown</span>
        <span itemprop="postalCode">98765</span>
      </span>
    </span>
  </div>
  <div id="employee-1" itemprop="employee" itemscope itemtype="http://scheR_810_11845@a.org/Person">
    <span itemprop="name">John Doe</span>,<span itemprop="jobtitle">SALEs Manager</span>
  </div>
</body>

给出以下内容

organization
  itemType = http://scheR_810_11845@a.org/Organization
  employee
    person
      itemType = http://scheR_810_11845@a.org/Person
      name = John Doe
      jobtitle = SALEs Manager
  name = Sun InduStries
  LOCATIOn
    place
      itemType = http://scheR_810_11845@a.org/Place
      address
        postaladdress
          itemType = http://scheR_810_11845@a.org/PostalAddress
          streetaddress = Technologies Street 42
          addresslocality = Venustown
          postalcode = 98765

或这个

<body>
  <div id="employee-1" itemscope itemtype="http://scheR_810_11845@a.org/Person">
    <span itemprop="name">John Doe</span>,<span itemprop="jobtitle">SALEs Manager</span>
    <Meta itemprop="worksFor" itemscope itemtype="http://scheR_810_11845@a.org/Organization"  itemref="organization">
  </div>
  <div id="organization">
    <span itemprop="name">Sun InduStries</span>,<span itemprop="addressLocality">Venustown</span>
        <span itemprop="postalCode">98765</span>
      </span>
    </span>
  </div>
</body>

结果

person
  itemType = http://scheR_810_11845@a.org/Person
  name = John Doe
  jobtitle = SALEs Manager
  worksfor
    organization
    itemType = http://scheR_810_11845@a.org/Organization
    name = Sun InduStries
    LOCATIOn
      place      
        itemType = http://scheR_810_11845@a.org/Place
        address
          postaladdress
            itemType = http://scheR_810_11845@a.org/PostalAddress
            streetaddress = Technologies Street 42
            addresslocality = Venustown
            postalcode = 98765

规范对于使用itemref并不是很清楚,但是例子有帮助

<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>

大佬总结

以上是大佬教程为你收集整理的HTML5 Microdata – itemref到另一个itemscope(Person适用于Organization)全部内容,希望文章能够帮你解决HTML5 Microdata – itemref到另一个itemscope(Person适用于Organization)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。