jQuery 如果在页面上找到此图像添加此元标记? [英] jQuery If this image is found on page add this meta tag?

查看:20
本文介绍了jQuery 如果在页面上找到此图像添加此元标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将丰富网页摘要添加到显示星星的动态图像中.我的购物车唯一写的是这张图片,所以我必须找到正在显示的图片,然后添加正确的元标记.

I am trying to add rich snippets to a dynamic image that displays stars. The only thing my shopping cart writes is this image so I have to find what image is being displayed then add the proper meta tag.

所以如果显示的图像是 1stars.gif 我必须写:

So if the image being displayed is 1stars.gif I have to write:

<meta itemprop="ratingValue" content="1" /> 

如果显示的图像是 5stars.gif 我必须写:

and if the image being displayed is 5stars.gif I have to write:

<meta itemprop="ratingValue" content="5" /> 

这是更新后的完整示例:

Here is the UPDATED full example:

<span id="rateitnow">
{module_ratingrank,images/icons/stars}
<meta itemprop="ratingValue" content="" />
</span>

<script type="text/javascript">
jQuery(document).ready(function($) { 
$('#rateitnow meta').attr('content', $('#rateitnow').find('img:first').attr('src').substr(0,1));
});
</script>

推荐答案

$('#rate-me meta').attr('content', $('#rate-me').find('img:first').attr('src').substr(0,1));

这篇关于jQuery 如果在页面上找到此图像添加此元标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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