JS allows you to calculate the number of mouse clicks on a page online. js clicks
This example describes how to use JavaScript to calculate the number of mouse clicks on a page online. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code is 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 records the number of mouse clicks </title>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312">
</Head>
<Body>
<Div id = "count"> </div> www.www.jb51.net 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 have not clicked! ";
AddCookie ("count", "0", "1000 ");
}
</Script>
</Body>
</Html>
I hope this article will help you design javascript programs.