Home > Web Front-end > JS Tutorial > js gets SMS verification code button countdown code

js gets SMS verification code button countdown code

小云云
Release: 2018-03-15 16:13:42
Original
3420 people have browsed it

This article mainly shares with you the js countdown code for getting the SMS verification code button. I hope it can help everyone.

  (function(){
        // 快速咨询
        $('#getCode').click(function() {
            var mobile = $('#mobile').val();//手机号码的值
            var _this = $(this);
            var mobileReg = /^1[3|4|5|7|8]\d{9}$/; //手机号正则
            var phoneflag = mobileReg.test(mobile);

            if (!phoneflag) {
                alert('手机号码格式不正确!');
            } else {

                //User/getCode.html这个是后台接口

                $.post("/User/getCode.html", {
                    mobile: mobile
                }, function(data) {
                    _this.attr("disabled", "disabled");
                        _this.css({background:"#eee"});//设置不可点颜色
                    var val = parseInt(_this.val());
                    var time = 60;
                    _this.val(time + " S");
                    time--;

                    var timer = setInterval(function() {
                        val = time + " S";
                        _this.val(val);
                        if (time > 0) {
                            time--;
                        } else {
                            //原始颜色
                            _this.val("获取验证码").removeAttr("disabled").css({background:"#66CCFF"});;
                            clearInterval(timer);
                        }
                    }, 1000);
                });
            }

        });
    })();
Copy after login

Rendering:

js gets SMS verification code button countdown code

Related recommendations:

js implementation of SMS verification code countdown example sharing

How to use php to implement SMS verification code sending

JS to implement SMS verification code

The above is the detailed content of js gets SMS verification code button countdown code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template