html - 如何为微数据嵌套 <meta> 标签?

标签 html meta schema.org microdata

我有这样的结构:

+ EVENT -> itemtype="http://schema.org/Event
 + Name   
 + Date   
 + ...
 + LOCATION -> itemtype="http://schema.org/Place
        *          Name
     + Url
     + ...

我不会在网站上显示所有地点信息,但我想将这些信息用于微数据。 所以我想添加这个标签:

<meta itemprop="location" itemscope itemtype="http://schema.org/Place">

工作正常。

但是我如何为nameurllocation添加itemprops?

它不会像这样工作:

<meta itemprop="location" itemscope itemtype="http://schema.org/Place">
<meta itemprop="url" content="https://example-location.com">
<meta itemprop="name" content="exampleLocationName">

最佳答案

大概是这样的。其实不太确定。

<meta itemprop="location" content="" itemscope itemtype="http://schema.org/Place" itemref="place-url place-name">
<link id="place-url" itemprop="url" href="https://example-location.com">
<meta id="place-name" itemprop="name" content="exampleLocationName">
<小时/>

你就不能把丑陋的空东西扔掉吗content

https://www.w3.org/TR/microdata#x7-2-content-models

If a meta element has an itemprop attribute, the name, http-equiv, and charset attributes must be omitted, and the content attribute must be present.

你不能。

为什么 <link>而不是<meta>

因为只有 URL 属性元素可以将绝对 URL 作为其值,并且 <link>一会儿<meta>不是。

来自https://www.w3.org/TR/microdata#x5-4-values-the-content-attribute-element-specific-attributes-and-element-content :

The algorithm to determine the value for a name-value pair is given by applying the first matching case in the following list:

  • If the element also has an itemscope attribute: the value is the item created by the element.
  • If the element has a content attribute: the value is the textContent of the element’s content attribute.

 

The URL property elements are the a, area, audio, embed, iframe, img, link, object, source, track, and video elements.

 

If a property’s value, as defined by the property’s definition, is an absolute URL, the property must be specified using a URL property element.

嵌套怎么样 <meta>标签?

你不能,因为 <meta>是一个 void 元素,它不能有任何子元素。

<小时/>

更好

您考虑过using JSON-LD相反?

关于html - 如何为微数据嵌套 &lt;meta&gt; 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42006735/

相关文章:

html - 内容安全策略存在问题

android - 移动网站在横向模式下的 Safari 上无法缩放

html - 我如何修改 Joomla 网站中的 <head> 标签?

schema.org - 不同 Schema.org 类型的几个 JSON-LD 脚本 : why they're combined into one type when testing with Google SDTT?

blogs - 使用 Schema.org 标记博客的首选方法

Javascript 相当于 $ ('input[name$="值"]') 在 jQuery 中?

html - 需要帮助使 div 垂直居中

escaping - 是否应转义JSON-LD字符串?

JavaScript 保留重复的内容

Javascript 点击功能不适用于自动打开