تصف هذه المقالة طريقة JS لحساب عدد نقرات الماوس في صفحة عبر الإنترنت. شاركه للرجوع إليه. طريقة التنفيذ المحددة هي كما يلي:
انسخ الرمز على النحو التالي: <! doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3
<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"> </viv> wulin.com www.vevb.com يطالبك:
<script type = "text/javaScript">
وظيفة AddCoOkie (الاسم ، cookievalue ، الوقت) {
if (name! = "" && cookievalue! = "" && time! = "") {
if (isnan (time) == false) {
var تنتهي = تاريخ جديد () ؛
Expires.Settime (Expires.getTime () + time * 1000) ؛
document.cookie = name + '=' + Escape (cookievalue) + '؛ Expires =' + Expires.TogMtString () ؛
}
}
}
وظيفة getCookie (Cookiename) {
var cookiestring = document.cookie ؛
var start = cookiestring.indexof (cookiename + '=') ؛
إذا (ابدأ == -1)
العودة لاغية.
ابدأ + = cookiename.length + 1 ؛
var end = cookiestring.indexof ('؛' ، start) ؛
if (end == -1) return unescape (cookiestring.substring (start)) ؛
إرجاع 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!" ؛
}آخر{
document.getElementById ("count"). innerhtml = "أنت لم تنقر عليه بعد!" ؛
AddCookie ("count" ، "0" ، "1000") ؛
}
</script>
</body>
</html>
آمل أن تكون هذه المقالة مفيدة لبرمجة JavaScript للجميع.