zoukankan      html  css  js  c++  java
  • Js获取验证码倒计时

    1.Jquery的实现:

    /**
    * 倒计时
    * e 代表发送按钮对象
    */
    function resetTime(e){
    var second = 60;
    var timer = null;
    timer = setInterval(function(){
    second -= 1;
    if(second >0){
    $(e).attr('disabled',true);
    $(e).text(second + "秒后获取验证码");
    }else{
    clearInterval(timer);
    $(e).attr('disabled',false);
    $(e).text("发送短信验证码");
    }
    },1000);
    }

    https://www.98891.com/article-96-1.html

    2、在vue实现倒计时获取验证码效果:

    这里我们没有使用setInterval,而使用setTimeout,每1秒钟递归来实现的。注意区别:

    <template>
    <div>
    <el-button :disabled="disabled" @click="sendcode" class="sendcode">{{btntxt}}</el-button>
    </div>
    </template>

    <script>
    export default {
    data() {
    return {
    disabled: false,
    time: 5,
    btntxt: "发送验证码",
    };
    },
    methods: {
    sendcode() {
    this.time = 5;
    this.timer();
    },
    //发送手机验证码倒计时
    timer() {
    if (this.time > 0) {
    this.disabled = true;
    this.time--;
    this.btntxt = this.time + "秒";
    setTimeout(this.timer, 1000);
    } else {
    this.time = 0;
    this.btntxt = "发送验证码";
    this.disabled = false;
    }
    },
    }
    }
    </script>

    <style scoped>
    .el-button {
    margin: 100px 50px;
    }
    </style>
  • 相关阅读:
    2016华中农业大学预赛 E 想法题
    2016华中农业大学预赛 B 数学
    render()
    钩子函数
    redirect_uri域名与后台配置不一致,错误码:10003
    群发次数
    表名
    intval()函数
    render()
    $this->autoRender = false
  • 原文地址:https://www.cnblogs.com/xiaonian8/p/14934048.html
Copyright © 2011-2022 走看看