JS实现在线统计一个页面内鼠标点击次数的方法
本文实例讲述了JS实现在线统计一个页面内鼠标点击次数的方法。分享给大家供大家参考。具体实现方法如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>js记录鼠标的点击次数</title>
<metahttp-equiv="content-type"content="text/html;charset=gb2312">
</head>
<body>
<divid="count"></div>毛票票www.nhooo.com提示您:
<scripttype="text/javascript">
functionaddCookie(name,cookievalue,time){
if(name!=""&&cookievalue!=""&& time!=""){
if(isNaN(time)==false){
varexpires=newDate();
expires.setTime(expires.getTime()+time*1000);
document.cookie=name+'='+escape(cookievalue)+';expires='+expires.toGMTString();
}
}
}
functiongetCookie(cookieName){
varcookieString=document.cookie;
varstart=cookieString.indexOf(cookieName+'=');
if(start==-1)
returnnull;
start+=cookieName.length+1;
varend=cookieString.indexOf(';',start);
if(end==-1)returnunescape(cookieString.substring(start));
returnunescape(cookieString.substring(start,end));
}
varhtml=document.getElementsByTagName("html")[0];
html.onclick=function(){
varcount=parseInt(getCookie('count'))+1;
addCookie("count",count,"1000");
document.getElementById("count").innerHTML="您点击了"+getCookie('count')+"次!";
}
if(getCookie('count')){
document.getElementById("count").innerHTML="您点击了"+getCookie('count')+"次!";
}else{
document.getElementById("count").innerHTML="您还没有点击过!";
addCookie("count","0","1000");
}
</script>
</body>
</html>
希望本文所述对大家的javascript程序设计有所帮助。
热门推荐
10 喜得孙子祝福语简短唯美
11 婚礼祝福语简短朴实大众
12 员工周年祝福语大全简短
13 家长回复节日祝福语简短
14 简短生日祝福语老同学
15 夜雨祝福语简短10字
16 蛋糕祝福语简短闺蜜
17 部门过年祝福语简短独特
18 简短精炼的结婚祝福语