定时短信验证(引用jquery)

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>10S后从新获取验证码</title>

</head>
<body>
<input id="send" type="button" value="发送验证码" />


<script src="jquery.min.js"></script>
<script>
//测试jquery可用
$('#send').css({color:'black', background:'#dfd'})
var times = 10;
var timer = "";
var send =$('#send');
$('body').on('click','#send',function(){
timer = setInterval(function(){
times--;
if(times<=0){
$('#send').val('发送验证码');
send.css({color:'black', background:'#dfd'});
clearInterval(timer);
//send.removeClass('disabled');

times=10;
send.attr('disabled',false);
}else{
send.css({color:'red', background:'#dfd'});
send.val(times+'秒后重试');
//send.disabled=true;

send.attr('disabled',true);
}
console.log(times);
},1000
)
})

</script>
</body>
</html>



原文地址:https://www.cnblogs.com/benbenjia/p/8929998.html