Home > Web Front-end > JS Tutorial > body text

js method to prevent repeated clicks or too fast clicks

PHPz
Release: 2018-10-10 16:19:05
forward
1563 people have browsed it

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>
Copy after login

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>
Copy after login

For more related tutorials, please visit JavaScript Video Tutorial

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template