JS allows you to calculate the number of mouse clicks on a page online. js clicks

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.