Home  >  Article  >  Web Front-end  >  js method to prevent repeated clicks or too fast clicks

js method to prevent repeated clicks or too fast clicks

PHPz
PHPzforward
2016-05-16 19:16:561526browse

js method to prevent repeated clicks or too fast clicks

1.html

<button type="button" data-val="0">00000</button>
<button type="button" data-val="1">11111</button>
<button type="button" data-val="2">22222</button>

2.js

<script>
	var isClick = true;
	$("button").on("click",function(){
		if(isClick) {
			isClick = false;
			//事件
			console.log($(this).attr("data-val"));
			//定时器
			setTimeout(function() {
				isClick = true;
			}, 1000);//一秒内不能重复点击
		}
	});
</script>

For more related tutorials, please visit JavaScript Video Tutorial

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete