js 点击获取验证码后的倒数60s

 

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8" />
		<script type="text/javascript">
			window.onload = function() {
				var getCheckNum = document.getElementById("getCheckNum");
				getCheckNum.onclick = function() {
					settime(this)
				}
			}
			var countdown = 60;

			function settime(obj) {
				if(countdown == 0) {
					obj.removeAttribute("disabled");
					obj.value = "免费获取验证码";
					countdown = 60;
					return;
				} else {
					obj.setAttribute("disabled", true);
					obj.value = countdown + "s";
					countdown--;
				}
				setTimeout(function() {
					settime(obj)
				}, 1000)
			}
		</script>
	</head>

	<body>
		<input type="button" class="getCheckNum" id="getCheckNum" value="免费获取验证码" />
	</body>

</html>

  

posted @ 2018-01-03 15:12  梁小清  阅读(706)  评论(0)    收藏  举报