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

<!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>

 

posted @ 2017-08-07 13:34  壁虎漫步.  阅读(193)  评论(0编辑  收藏  举报