This article describes the method of JS to calculate the number of mouse clicks in a page online. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>js record the number of clicks on the mouse</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
</head>
<body>
<div id="count"></div>Wulin.com www.VeVB.COM prompts you:
<script type="text/javascript">
function addCookie(name,cookievalue,time) {
if (name != "" && cookievalue != "" && time != "") {
if (isNaN(time) == false){
var expires = new Date();
expires.setTime(expires.getTime() + time * 1000);
document.cookie = name + '=' + escape(cookievalue) + ';expires=' + expires.toGMTString();
}
}
}
function getCookie(cookieName) {
var cookieString = document.cookie;
var start = cookieString.indexOf(cookieName + '=');
if (start == -1)
return null;
start += cookieName.length + 1;
var end = cookieString.indexOf(';', start);
if (end == -1) return unescape(cookieString.substring(start));
return unescape(cookieString.substring(start, end));
}
var html = document.getElementsByTagName("html")[0];
html.onclick = function(){
var count = parseInt(getCookie('count'))+1;
addCookie("count",count,"1000");
document.getElementById("count").innerHTML = "You clicked "+getCookie('count')+" times!";
}
if (getCookie('count')){
document.getElementById("count").innerHTML = "You clicked "+getCookie('count')+" times!";
}else{
document.getElementById("count").innerHTML = "You haven't clicked it yet!";
addCookie("count","0","1000");
}
</script>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.