zoukankan      html  css  js  c++  java
  • js,jq发送短信倒计时

    js:

    <input type="button" id="btn" value="免费获取验证码" />

    <script type="text/javascript">
    var wait=60;
    function time(o) {
            if (wait == 0) {
                o.removeAttribute("disabled");            
                o.value="免费获取验证码";
                wait = 60;
            } else { // www.jbxue.com
                o.setAttribute("disabled", true);
                o.value="重新发送(" + wait + ")";
                wait--;
                setTimeout(function() {
                    time(o)
                },
                1000)
            }
        }
    document.getElementById("btn").onclick=function(){time(this);}

    </script>

    jq:(js的那个在我的项目上不是很好用自己写了一个jq的)

                var step = 59;
                $('#btn').val('重新发送60');
                var _res = setInterval(function()
                {   
                    $("#btn").attr("disabled", true);//设置disabled属性
                    $('#btn').val('重新发送'+step);
                    step-=1;
                    if(step <= 0){
                    $("#btn").removeAttr("disabled"); //移除disabled属性
                    $('#btn').val('获取验证码');
                    clearInterval(_res);//清除setInterval
                    }
                },1000);

    转自http://blog.csdn.net/yanfangphp/article/details/21469755

  • 相关阅读:
    菜鸟打印模板
    centos8安装nginx1.9.1
    centos8安装tomcat8.5
    构建微信公众号服务实例和小程序服务实例
    wxMpMenuService.menuGet()和wxMpMenuService.getSelfMenuInfo()返回值对比
    spring cloud 实现基于Nacos权重的负载均衡
    go开发环境搭建
    国内公共的DNS服务&Centos7 配置公共DNS服务
    Redis
    Spring Boot 集成 PageHelper
  • 原文地址:https://www.cnblogs.com/liziqiang/p/4081170.html
Copyright © 2011-2022 走看看