Javascript 60s倒计时代码

  • Post author:
  • Post category:java


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript"> 
var countdown=60; 
function sendCode(){
    var a = $("#btn");
    outtime(a);
    
    }
function outtime(o) { //发送验证码倒计时
    if (countdown == 0) { 
        o.attr('disabled',false);          
        o.val("获取验证码");
        countdown = 60; 
        return;
    } else { 
        o.attr('disabled',true);
        o.val("重新发送验证码(" + countdown + ")");
        countdown--; 
    } 
setTimeout(function() { 
    outtime(a) }
    ,1000) 
}
</script>
<body> 
<input type="button" id="btn" value="获取验证码" onclick="sendCode()" /> 
  
</body>
</html>



版权声明:本文为weixin_41302755原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。