首页 > Web开发 > 详细

js 验证码 倒计时60秒

时间:2017-11-17 16:00:58      阅读:220      评论:0      收藏:0      [点我收藏+]

JS代码

    <script type="text/javascript">
        $(function () {
            var countdown = 60;

            function settime() {
                if (countdown == 0) {
                    $(‘.getYZM‘).html("获取验证码");
                    countdown = 60;
                    return false;
                } else {
                    $(‘.getYZM‘).html("重新获取倒计时:" + countdown + "s");
                    countdown--;
                }
                setTimeout(function () {
                    settime();
                }, 1000);
            }

            $(‘.getYZM‘).click(function () {
                var phone = $(‘input[name="phone"]‘).val();
                if (phone == "") {
                    layer.msg(‘请输入手机号码‘);
                    return;
                }
                if (!checkMobile(phone)) {
                    layer.msg(‘请输入正确手机号码‘);
                    return;
                }

                var thisVal = $(this).html();

                console.log(thisVal);
                if (thisVal == "获取验证码") {
                    settime();
                    $.ajax({
                        url: "../ajax.aspx?act=GetIdentifyingcode&s=" + phone + ",1",
                        type: "post",
                        success: function (data) {
                            layer.msg(data);
                            console.log(data);
                        }
                    });
                }
            });

            function checkMobile(phone) {
                if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(phone))) {
                    console.log(‘false‘);
                    $(‘input[name="phone"]‘).focus();
                    return false;
                } else {
                    return true;
                }
            }
        });
    </script>

 最终效果

技术分享图片技术分享图片

 

js 验证码 倒计时60秒

原文:http://www.cnblogs.com/baocaige/p/7851693.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!