本文实例讲述了JS实现在线统计一个页面内鼠标点击次数的方法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下: js记录鼠标的点击次数 脚本之家 www.jb51.net 提示您: <br> function addCookie(name,cookievalue,time) {<br> if (name != "" && cookievalue != "" && time != "") {<br> if (isNaN(time) == false){<br> var expires = new Date();<br> expires.setTime(expires.getTime() time * 1000);<br> document.cookie = name '=' escape(cookievalue) ';expires=' expires.toGMTString();<br> }<br> }<br> }<br> function getCookie(cookieName) {<br> var cookieString = document.cookie;<br> var start = cookieString.indexOf(cookieName '=');<br> if (start == -1)<br> return null;<br> start = cookieName.length 1;<br> var end = cookieString.indexOf(';', start);<br> if (end == -1) return unescape(cookieString.substring(start));<br> return unescape(cookieString.substring(start, end));<br> }<br> var html = document.getElementsByTagName("html")[0];<br> html.onclick = function(){<br> var count = parseInt(getCookie('count')) 1;<br> addCookie("count",count,"1000");<br> document.getElementById("count").innerHTML = "您点击了" getCookie('count') "次!";<br> }<br> if (getCookie('count')){<br> document.getElementById("count").innerHTML = "您点击了" getCookie('count') "次!";<br> }else{<br> document.getElementById("count").innerHTML = "您还没有点击过!";<br> addCookie("count","0","1000");<br> }<br> 希望本文所述对大家的javascript程序设计有所帮助。