<a href="#" onclick="countNumber()">点击</a>
<script type="text/javascript">
if(!localStorage.countAll){
localStorage.countAll = 0
}
document.getElementById('countspan').innerHTML = localStorage.countAll
function countNumber(){
localStorage.countAll++
document.getElementById('countspan').innerHTML = localStorage.countAll
}
</script>
支持html5的浏览器都能用。
phpcms v9增加文章随机点击数的方法:找到文件count.php(网站根目录/api)
查找第50行,找到这段代码$views = $r['views'] + 1这里的1是默认的,表示每浏览一次,点击量增加一次,可以修改成自己想要的任意数字
或者$views = $r['views'] + rand(10,100) 随机的增加 10到100之间的一个任意的整数;
1,首页调用点击量
{pc:content action="lists" catid="$r[catid]" num="5" order="id DESC" return="info"}
{php $categorys = getcache('category_content_'.$siteid,'commons')}
{loop $info $v}
{php $category = $categorys[$v[catid]]}
{php $modelid = $category['modelid']}
{php $db = pc_base::load_model('hits_model') $_r = $db->get_one(array('hitsid'=>'c-'.$modelid.'-'.$v[id]))$views = $_r[views]}
{php $comment_tag = pc_base::load_app_class("comment_tag", "comment")$comment_total = $comment_tag->count(array('commentid'=>'content_'.$v[catid].'-'.$v[id].'-'.$modelid))}
·{str_cut($v['title'],40)} 点击:{$views} 评论:{if $comment_total}{$comment_total}{else}0{/if}
{/loop}
{/pc}
2,列表页调取点击量
{php $db = pc_base::load_model(‘hits_model’)$_r = $db->get_one(array(‘hitsid’=>’c-’.$modelid.’-’.$r[id]))$views = $_r[views]}
点击:{$views}
3, 内容页调取点击量
<\script type="text/javascript" src="{JS_PATH}jquery.min.js">
<\span id="hits"><\script language="JavaScript" src="{APP_PATH}api.php?op=count&id={$id}&modelid={$modelid}"><\/span>