<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript">
var times = 0;//点击次数
var preClickTime ;//上一次点击的时间(毫秒)
var currentClickTime;//当前点击时间
function countClickedTimes(){
if(times === 0){
preClickTime = new Date().getTime();//首次点击的时间
times ++;
alert("当前点击次数:"+times);
return;
}
currentClickTime = new Date().getTime();
//alert(currentClickTime - preClickTime);
if((currentClickTime - preClickTime) < 3000) {//如果是3秒内重复点击
alert("亲,您的点击速度过快...");
preClickTime = currentClickTime;
return;
}
preClickTime = currentClickTime;
times ++ ;
alert("当前点击次数:"+times);
}
</script>
</head>
<body>
<a href="javascript:countClickedTimes();">统计点击次数</a>
</body>
</html>统计鼠标点击次数的页面demo
最新推荐文章于 2026-04-06 03:05:03 发布
本文介绍了一个简单的JavaScript脚本,用于记录用户在一个网页元素上的点击次数,并通过判断两次点击的时间间隔来防止短时间内重复点击的问题。
该文章已生成可运行项目,
本文章已经生成可运行项目

2349

被折叠的 条评论
为什么被折叠?



