jQuery实现倒计时重新发送短信验证码功能示例

时间:2021-05-25 15:46:57
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery实现倒计时重新发送短信验证码功能示例-jq22.com</title>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<style>
</style>
</head>
<body>
<input type="button" id="btn" value="免费获取验证码" onclick="settime(this)"><script>
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 + ")";
countdown--;
}
setTimeout(function() {
settime(obj) }
,1000)
}</script>
</body>
</html>