短信验证码js


var isSmsSend = false;
    function clickButtona(obj){  

            var obj = $(obj); 
            var mobile=$("input[name=mobile]").val(); 
            var URL1 = "{:url('member/index/getcode')}";
            if(isSmsSend == false){
                isSmsSend = true;
                $.ajax({
                url: URL1,
                type: 'post',
                data:{mobile:mobile},
                success: function(data) {

                     if(data.error>0){
                        isSmsSend = false;
                        layer.open({
                            content: data.msg
                            ,skin: 'msg'
                            ,time: 2 //2秒后自动关闭
                        }); 
                        return false;
                    }else{   
                         layer.open({
                            content: "验证码已发送,请注意查收"
                            ,skin: 'msg'
                            ,time: 2 //2秒后自动关闭
                        }); 
                        obj.attr("disabled","disabled");/*按钮倒计时*/ 
                        var time = 60; 
                        var set = setInterval(function(){
                            if(time >= 0){
                                obj.val(time+"(s)"); 
                            }else{
                                isSmsSend = false;
                                clearInterval(set);
                                obj.attr("disabled",false);
                                obj.val("重新发送"); 
                            }
                            time--;
                            
                        }, 1000);/*等待时间*/  

                    } 
                } 
            });
            }
            
        }

posted @ 2018-12-31 19:54  sfornt  阅读(247)  评论(0编辑  收藏  举报