欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JS+HTML5实现获取手机验证码倒计时按钮

程序员文章站 2022-06-30 18:21:52
效果图如下所示: html: css: input...

效果图如下所示:

JS+HTML5实现获取手机验证码倒计时按钮

html:

 <input type="button" value="获取验证码"> 

css:

 input[type=button]
  width: 150px;
  height: 30px;
  background-color: #ff3000;
  border: 0;
  border-radius: 15px;
  color: #fff;
 }
 input[type=button].on {
  background-color: #eee;
  color: #ccc;
  cursor: not-allowed;
 }

javascript:

 $("input[type='button']").click(btncheck);
  /**
  * [btncheck 按钮倒计时常用于获取手机短信验证码]
  */
  function btncheck() {
   $(this).addclass("on");
   var time = 5;
   $(this).attr("disabled", true);
   var timer = setinterval(function() {
    if (time == 0) {
     clearinterval(timer);
     $("input").attr("disabled", false);
     $("input").val("获取验证码");
     $("input").removeclass("on");
    } else {
     $('input').val(time + "秒");
     time--;
    }
   }, 1000);
  }

github:fuck me on github fuck me on github

总结

以上所述是小编给大家介绍的js+html5实现获取手机验证码倒计时按钮,希望对大家有所帮助