Heim  >  Artikel  >  Web-Frontend  >  js防止重复点击或者点击过快方法

js防止重复点击或者点击过快方法

PHPz
PHPznach vorne
2016-05-16 19:16:561527Durchsuche

js防止重复点击或者点击过快方法

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>

 更多相关教程请访问  JavaScript视频教程

Stellungnahme:
Dieser Artikel ist reproduziert unter:csdn.net. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen