บทความนี้อธิบายวิธีการของ JS ในการคำนวณจำนวนการคลิกเมาส์ในหน้าออนไลน์ แบ่งปันสำหรับการอ้างอิงของคุณ วิธีการใช้งานเฉพาะมีดังนี้:
คัดลอกรหัสดังนี้: <! 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 บันทึกจำนวนคลิกบนเมาส์ </title>
<meta http-equiv = "content-type" content = "text/html; charset = gb2312">>
</head>
<body>
<div id = "count"> </div> wulin.com www.vevb.com แจ้งให้คุณทราบ:
<script type = "text/javascript">
ฟังก์ชั่น addCookie (ชื่อ, cookievea, เวลา) {
if (name! = "" && cookieViewalue! = "" && time! = "") {
if (isnan (เวลา) == false) {
var expires = date ใหม่ ();
Expires.settime (Expires.getTime () + เวลา * 1000);
document.cookie = name + '=' + escape (cookievalue) + '; expires =' + expires.togmtstring ();
-
-
-
ฟังก์ชั่น getCookie (cookiename) {
var cookiestring = document.cookie;
var start = cookiestring.indexof (cookiename + '=');
if (start == -1)
คืนค่า null;
start + = cookiename.length + 1;
var end = cookiestring.indexof (';', start);
if (end == -1) ส่งคืน Unsescape (cookiestring.substring (เริ่มต้น));
ส่งคืน Unsescape (cookiestring.substring (เริ่มต้นสิ้นสุด));
-
var html = document.getElementsByTagname ("html") [0];
html.onclick = function () {
var count = parseInt (getCookie ('count'))+1;
addcookie ("count", count, "1,000");
document.getElementById ("count"). innerhtml = "คุณคลิก"+getCookie ('count')+"Times!";
-
if (getCookie ('count')) {
document.getElementById ("count"). innerhtml = "คุณคลิก"+getCookie ('count')+"Times!";
}อื่น{
document.getElementById ("count"). innerhtml = "คุณยังไม่ได้คลิก!";
addcookie ("count", "0", "1,000");
-
</script>
</body>
</html>
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน