短信验证码+倒计时


function sendMsg() { var phone = $("#labPhone input").val(); //经办人手机号 $.ajax({ type: "Post", url: "/Views/SMS/Index.html?Action=SendCaptchaMessage", data: { phoneNumber: phone }, dataType: "json", success: function (data) { if (data.Success == true) { $("#aGetdata").html(time + "秒"); InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器,1秒执行一次 } else { $("#yzmImg").attr("src", "/Views/SMS/Index.html?Action=GetCaptchaImage&time=" + new Date()); $("#dxyam").addClass("inpError").siblings(".errorTxt").show().html("不正确或超时"); //alert(data.Message); } } }) } function sendMessage() { var iPhone = $("#labPhone input").val(); //经办人手机号 var yzm = $("#apply0 input[name='yzm']").val(); var code = $("#code").val(); var telReg = !!iPhone.match(regulars.iPhone); if (telReg == false) { $("#labPhone input").addClass("inpError").siblings(".errorTxt").show().html("请输入正确的手机号"); $("#labPhone input").siblings(".labOk").remove(); } else { $.ajax({ type: "Post", url: "/Views/SMS/Index.html?Action=VerifyCaptcha", data: { captchaCode: code }, dataType: "json", success: function (data) { if (data.Success == true) { t = time; $("#code").removeClass("inpError").siblings(".errorTxt").hide(); $("#aGetdata").removeAttr("href"); $("#aGetdata").html(t + "秒"); InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器,1秒执行一次 } else { $("#yzmImg").attr("src", "/Views/SMS/Index.html?Action=GetCaptchaImage&time=" + new Date()); $("#code").addClass("inpError").siblings(".errorTxt").show().html("验证码不正确"); } } }) } } function SetRemainTime() { if (t == 0) { window.clearInterval(InterValObj); $("#aGetdata").attr("href", "javascript:sendMessage()"); //启用按钮 $("#aGetdata").html("重新发送验证码"); $("#code").attr("value",""); $("#yzmImg").attr("src", "/Views/SMS/Index.html?Action=GetCaptchaImage&time=" + new Date()); } else { t--; $("#aGetdata").html(t + "秒"); } }

 function addApplyerInfo(){
                   $("#labApplyer0 input").val($("#labApplyer input").val()); //经办人
                   $("#labIdentyNumber0 input").val($("#labIdentyNumber input").val()); //经办人证件号
                   $("#labPhone0 input").val($("#labPhone input").val()); //经办人手机
               }

               $("#nextStep").click(function () {
                   $("#apply0 input").each(function () {
                       if ($(this).val().length == "") {
                           if (this.name == "name") {
                               $(this).addClass("inpError").siblings(".errorTxt").show().html("请输入姓名");
                           } else if (this.name == "idCard") {
                               $(this).addClass("inpError").siblings(".errorTxt").show().html("请输入身份证信息");
                           } else if (this.name == "phone") {
                               $(this).addClass("inpError").siblings(".errorTxt").show().html("请输入手机号码");
                           } else if (this.name == "yzm") {
                               $(this).addClass("inpError").siblings(".errorTxt").show().html("请输入验证码");
                           }
                       }


                   })
                   if ($("#apply0 .inpError").length == 0 && $("#apply0 .labOk").length == 3) {
                       var code = $.trim($("#dxyzm").val());
                       if (code.length > 0) {
                           $.ajax({
                               type: "Post",
                               url: "/Views/SMS/Index.html?Action=VerifyMessageCaptcha",
                               data: { messageCode: code },
                               dataType: "json",
                               success: function (data) {
                                   if (data.Success == true) {
                                       addApplyerInfo();
                                       $("#apply0").hide();
                                       $("#dSignet").show();
                                       inputList();
                                   } else {
                                       alert(data.Message);
                                       addApplyerInfo();$("#apply0").hide();
                                       $("#dSignet").show();
                                       inputList();
                                   }
                               }
                           });
                       } else {
                           $("#dxyzm").addClass("inpError").siblings(".errorTxt").show().html("请输入验证码");
                       }

                   } else {
                       return
                   }

               })

 

            <div id="apply0">
            <!--经办人信息填写-->
            <div class="dHead">
                    经办人信息填写</div>
                    <div class="dBody">
            <div class="item">
                <span class="sTitle"><b>*</b>经办人姓名:</span>
                <div class="dInf" id="labApplyer"><input name="name" type="text" value=""  /><label class="errorTxt"></label></div>
            </div>
            <div class="item">
                <span class="sTitle"><b>*</b>身份证号:</span>
                <div class="dInf" id="labIdentyNumber"><input name="idCard" type="text" value=""  /><label class="errorTxt"></label></div>
            </div>
            <div class="item">
                <span class="sTitle"><b>*</b>手机号:</span>
                <div class="dInf" id="labPhone"><input name="phone" type="text" value="" /><label class="errorTxt"></label></div>
            </div>
            <div class="item ">
                <span class="sTitle "><b>*</b>验证码:</span>
                <div class="dInf yzm"><input name="yzm" type="text" value="" style=" width:100px; float:left" id="code"/><label class="labImg"><img  src="/Views/SMS/Index.html?Action=GetCaptchaImage" width="104" height="38" onclick="changeImg()"  alt="验证码" id="yzmImg" /></label><label class="labTxt"> 看不清?<a href="javascript:void(0);" class="blue" id="changeImg" onclick="changeImg()">换一张</a></label><label class="errorTxt" style=" width:100px"></label></div>
            </div>
            <div class="item">
                <span class="sTitle"><b>*</b>短信验证码:</span>
                <div class="dInf"><input name="dxyzm" type="text" value="" style=" width:120px; float:left" id="dxyzm" /><a class="aBtn" id="aGetdata" href="javascript:sendMessage()">获取短信验证码</a><label class="errorTxt" style=" width:140px"></label></div>
            </div>
            <div class="clear"></div>
            <div class="next" style=" width:600px">
                    <a id="nextStep">下一步</a> </div>
            </div>
            </div>

 

posted @ 2015-12-30 17:15  纳闷儿  阅读(420)  评论(0编辑  收藏  举报