jQuery如果这个图像在页面上找到添加此元标记? [英] jQuery If this image is found on page add this meta tag?
本文介绍了jQuery如果这个图像在页面上找到添加此元标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以如果显示的图像是1stars .gif我必须写:
< meta itemprop =ratingValuecontent =1/>
如果显示的图像是5stars.gif我必须写:
< meta itemprop =ratingValuecontent =5/>
以下是UPDATED完整示例:
< span id =rateitnow>
{module_ratingrank,images / icons / stars}
< meta itemprop =ratingValuecontent =/>
< / span>
< script type =text / javascript>
jQuery(document).ready(function($){
$('#rateitnow meta')。attr('content',$('#rateitnow')。find('img:first' ).attr('src')。substr(0,1));
});
< / script>
解决方案
$ (''src')。substr(0,1));('''''''')。
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.
So if the image being displayed is 1stars.gif I have to write:
<meta itemprop="ratingValue" content="1" />
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屋!
查看全文