如何添加“姓名”和“url”相同标签的属性?
我正在将 schema.org 微数据添加到我的网站。
我的HTML代码是这样的:
<div itemscope itemtype="http://schema.org/Organization">
<span class="title">Name of the organization</span>
<a href="http://www.ABCCompany.com/">ABC Company</a>
</div>
由于组织的itemprop
“url”和“name”都在锚标记中。如何在同一标签上同时指示“url”和“name”itemprop
?为此,我必须添加额外的 span
标签吗?
我尝试搜索一些相关的编码示例,但找不到任何示例来显示在同一标签上使用多个 itemprop
。
最后,我想要这样的微数据:
url="http://www.ABCCompany.com", name="ABC Company"
I'm adding the schema.org Microdata to my website.
My HTML code is like this:
<div itemscope itemtype="http://schema.org/Organization">
<span class="title">Name of the organization</span>
<a href="http://www.ABCCompany.com/">ABC Company</a>
</div>
Since the itemprop
"url" and "name" of the Organization are all in the anchor tag. How can I indicate the both "url" and "name" itemprop
on the same tag? Must I add extra span
tag for this purpose?
I have tried searching some coding examples on this but cannot find any example to show the use of multiple itemprop
on the same tag.
At the end, I want to have Microdata like this:
url="http://www.ABCCompany.com", name="ABC Company"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您必须通过嵌套两个元素来做到这一点。例如,您可以将
嵌套在
内,并将
itemprop="name"
放在上面:I找到这个网站来方便地测试这些东西。
You have to do it by nesting two elements. For example, you can nest a
<span>
inside the<a>
and put theitemprop="name"
on that:I find this site handy for testing such things.
谷歌可能有问题。 “丰富的摘要测试工具”表明,当您将锚标记标记为网址时,标记的正文将用作值而不是 href 属性。但没有人愿意在锚标记内显示 url。
There may be a problem with google. The "rich snippets testing tool" indicates that when you mark an anchor tag as a url, the body of the tag is used as value rather than the href attribute. But nobody wants to display the url inside an anchor tag.
这也有效,并且可能看起来更容易维护:
Google 对 schema.org 和 的支持自从最初的问题发布以来,谷歌结构化数据测试器已经有了很大的改进。上面的代码在其中验证正确。
This also works and may look a bit easier to maintain:
Google's support for schema.org and the google structured data tester have improved considerably since the original question was posted. The code above validates correctly in it.
OP的原始代码现在似乎可以正常工作。如图所示:
GLA 250 4MATIC< /跨度>
The OP's original code now seems to work ok. As shown here:
<div itemscope="" itemtype="http://schema.org/Organization">
<span class="title" itemprop="name">
<a itemprop="url" href="http://mercedes-benzhanoi.com.vn/mercedes-ha-noi.auto/gla-250-4matic.html">GLA 250 4MATIC</a></span>
</div>