博客园 顶部的随笔、文章、评论的总数统计是通过什么函数获取到的?我想要函数名,然后自己放在其他位置
我在自定义我的博客,这是我的地址http://www.cnblogs.com/dinphy/
可以在页面加载完后,使用jQuery
查找,比如,随笔数量:
var num1 = $('#sidebar_postarchive>h3>span').html().replace(/\(|\)/g,"");
文章总数量:
var num2 = $('#sidebar_articlearchive>h3>span').html().replace(/\(|\)/g,"");
我想通过后台函数调用,前台直接显示出来。
比如,后台是:随笔 - 函数名(参数)
前台就是:随笔 - 15
@dinphy: 是可以的,你可以去我的博客看下:
@dinphy:
在适当位置添加一个标签,例如:
<div id="stats_count_show"></div>
添加js代码:
<script type="text/javascript">
$(function() {
setTimeout(getAllCount, 3000);
function getAllCount() {
var post = document.getElementById('stats_post_count').innerText.replace(/.*?(\d+).*?/g, '$1');
var article = document.getElementById('stats_article_count').innerText.replace(/.*?(\d+).*?/g, '$1');
var comment = document.getElementById('stats-comment_count').innerText.replace(/.*?(\d+).*?/g, '$1');
post = post != null || post != "" ? post : 0;
article = article != null || article != "" ? article : 0;
comment = comment != null || comment != "" ? comment : 0;
document.getElementById('stats_count_show').innerText = "随笔:[" + post + "]篇;文章[" + article + "]篇;评论:[" + comment + "]条.";
}
});
</script>
效果:
@SeayXu: 灰常感谢
不是通过ajax获取的,目前没有对应的js函数