Home Web Front-end JS Tutorial JS method to implement online counting of mouse clicks on a page_javascript skills

JS method to implement online counting of mouse clicks on a page_javascript skills

May 16, 2016 pm 04:12 PM
js method page mouse

The example in this article describes the JS method of online counting the number of mouse clicks on a page. Share it with everyone for your reference. The specific implementation method is as follows:

Copy code The 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>Script Home www.jb51.net reminds 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 yet!";
addCookie("count","0","1000");
}
</script>
</body>
</html>

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel. How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel. Mar 28, 2024 pm 12:50 PM

How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel.

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) May 01, 2024 pm 12:01 PM

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts)

HP launches Professor 1 three-mode soft mouse: 4000DPI, Blue Shadow RAW3220, initial price 99 yuan HP launches Professor 1 three-mode soft mouse: 4000DPI, Blue Shadow RAW3220, initial price 99 yuan Apr 01, 2024 am 09:11 AM

HP launches Professor 1 three-mode soft mouse: 4000DPI, Blue Shadow RAW3220, initial price 99 yuan

Razer | Pokémon Gengar wireless mouse and mouse pad are now available, with a set price of 1,549 yuan Razer | Pokémon Gengar wireless mouse and mouse pad are now available, with a set price of 1,549 yuan Jul 19, 2024 am 04:17 AM

Razer | Pokémon Gengar wireless mouse and mouse pad are now available, with a set price of 1,549 yuan

VGN co-branded 'Elden's Circle' keyboard and mouse series products are now on the shelves: Lani / Faded One custom theme, starting from 99 yuan VGN co-branded 'Elden's Circle' keyboard and mouse series products are now on the shelves: Lani / Faded One custom theme, starting from 99 yuan Aug 12, 2024 pm 10:45 PM

VGN co-branded 'Elden's Circle' keyboard and mouse series products are now on the shelves: Lani / Faded One custom theme, starting from 99 yuan

Quickly master: How to open two WeChat accounts on Huawei mobile phones revealed! Quickly master: How to open two WeChat accounts on Huawei mobile phones revealed! Mar 23, 2024 am 10:42 AM

Quickly master: How to open two WeChat accounts on Huawei mobile phones revealed!

The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) May 04, 2024 pm 06:01 PM

The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs)

How to set font size on mobile phone (easily adjust font size on mobile phone) How to set font size on mobile phone (easily adjust font size on mobile phone) May 07, 2024 pm 03:34 PM

How to set font size on mobile phone (easily adjust font size on mobile phone)

See all articles