我在图库网站上使用了Facebook评论。我使用Facebook功能在相册视图中的缩略图下显示评论数。
https://developers.facebook.com/docs/plugins/comments
我想要一个使用span类进行不同颜色编码的javascript代码。例如,当评论数大于0时,我希望它是红色的。
<html><head></head><body>
<fb:comments-count class="" href="http://www.example.com/pic1.html" fb-xfbml-state="rendered">
<span class="fb_comments_count">0</span>
</fb:comments-count>
<fb:comments-count class="" href="http://www.example.com/pic2.html" fb-xfbml-state="rendered">
<span class="fb_comments_count">3</span>
</fb:comments-count>
<fb:comments-count class="" href="http://www.example.com/pic3.html" fb-xfbml-state="rendered">
<span class="fb_comments_count">0</span>
</fb:comments-count>
</body></html>
我已经尝试过类似http://jsfiddle.net/eliz82/6eo7s0ud/的方法,但是它不起作用,我认为使用搜索而不是数学函数不是很好。
最佳答案
所以我设法使用以下类似的代码建立了这个工作基地:change row color if row value is negative
但是我有一个问题,当我做实际工作时,不仅是简单的html测试。
执行我的JavaScript后呈现的Facebook评论数。所以我没工作
我必须使用此代码:http://css-tricks.com/snippets/jquery/run-javascript-only-after-entire-page-has-loaded/
在我执行代码之前
所以脚本是这样的:
$(window).bind("load", function() {
$("span.fb_comments_count")
.filter(function () {
return $(this).html() > 0;
})
.parent().css('color', 'red');
});
关于javascript - 如果大于0(零),则Facebook评论计数不同的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28086487/