是否可以使用jQuery更改Microdata itemprop? [英] Is it possible to change Microdata itemprop with jQuery?

查看:107
本文介绍了是否可以使用jQuery更改Microdata itemprop?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在控制台日志中显示成功,但在使用Google的结构化数据测试工具或G +共享按钮进行测试时失败.原始值保持不变.在这种情况下,"jack"永远不会更新为"jill".

Here is the code that shows success in console log but fails when tested with Google's Structured Data Testing Tool or with G+ share button. The original values remain. In this case "jack" never updates to "jill".

var newName= "jill"
$("h1").attr('itemprop','name').html(newName);

这是微数据:

<body itemscope itemtype="http://schema.org/Blog">

<div style="display:none;"> 
<h1 itemprop="name">jack</h1>
<img itemprop="image" src="http://somehewhere.com/something.png" />
<p itemprop="description">some text</p>

</div>

如您所见,只是尝试将"jack"的值更改为"jill".

As you can see, just trying to change the value of "jack" to "jill".

推荐答案

不能在itemprop属性上使用html()方法.您需要将其仅应用于h1标签:

The html() method cannot be used on the itemprop attribute. You need to apply it to just the h1 tag instead:

$("h1[itemprop=name]").html(newName);

或者因为newName是简单文本:

or since newName is simple text:

$("h1[itemprop=name]").text(newName);

这篇关于是否可以使用jQuery更改Microdata itemprop?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆