0

I am currently trying to mark up my website product pages with product rating microdata for google SERP benefits.

The current cart software I am using does have a product rating system. It generates the following html related to the product's rating:

<span id="dnn_ctr783_ProductDetails_ctl02_lblAvgStars2">Average Rating: 5 Stars</span>

I am able to add the schema.org identifier to this span tag to produce the following:

<span id="dnn_ctr783_ProductDetails_ctl02_lblAvgStars2" itemprop="ratingValue">Average Rating: 5 Stars</span>

However, the value specified in the span tag is not valid with schema.org. They require that the "ratingValue" only contain a single digit to specify the rating. My span tag has a lot of additional text.

Somehow, I need to pull the number "5" from the generated rating span tag, and write it into another span tag which will have the proper value for the schema.org product markup.

Any ideas on how to accomplish this? Thanks!

4

3 回答 3

0

您能否详细说明如何创建和使用此跨度?如果您只想要具有“itemprop”属性的跨度中的单个数字,这应该会获得您的价值。

$('[itemprop="ratingValue"]').text().match(/\d/g)
于 2013-06-18T21:37:01.053 回答
0

请注意,搜索引擎在抓取您的网站时不太可能执行任何类型的 javascript,因此该技术仅适用于常规浏览器,但对搜索引擎无效。

于 2013-06-19T02:23:25.687 回答
0
$('[itemprop="ratingValue"]').each(function() {
   var txt = $(this).text(),
       rating = txt.replace(/\D/g, '' );
       // This will replace all the non-numeric instances

   $('<span/>', {
      'class' : 'newRatingValue',
      text    : rating
   }).appendTo('#div1');
   // Append this to a new span and remove the current span
   $(this).remove();
});

检查小提琴

于 2013-06-18T21:35:21.287 回答