< script language="javascript" type="application/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;
}
times ++ ;
preClickTime = currentClickTime;
alert("当前点击次数:"+times);
}
< /script>
< body>
<a href="javascript:countClickedTimes();">统计点击次数</a>
< /bo dy>
Javascript防止短时间内button被点击多次
最新推荐文章于 2022-09-23 13:56:02 发布