<input id="code" name="code" type="text" placeholder="验证码" maxlength="6" datatype="*" nullmsg="验证码"> <a onClick="sendMessage();" id="get_smscode"><span id="get_smscode_val">获取验证码</span></a> // 发送验证码 function sendMessage(){ var user_telephone = $("#user_telephone").val(); if(user_telephone == ''){ alert("请输入手机号码"); return false; } if(!/^1[345789]\d{9}$/.test(user_telephone)){ alert("请输入正确的手机号码"); return false; } var count = 60; var countdown; $.ajax({ type:"post", url:"{:url('doSendMessage')}", data:"user_telephone="+user_telephone,//这里data传递过去的是序列化以后的字符串 success:function(data){ if(data.msg == '发送成功'){ countdown = setInterval(CountDown, 1000); } } }); // 发送短信倒计时 function CountDown() {
// disabled true可点 $("#get_smscode").attr("disabled", true).css("background-color", "#ffffff"); $("#get_smscode").css("color", "#cccccc"); $("#get_smscode").css("border", "1px solid #cccccc"); $("#get_smscode_val").html(count + "秒后获取"); if (count == 0) {
// disabled 不可点 $("#get_smscode").removeAttr("disabled").css("background-color", "#ffffff"); $("#get_smscode").css("color", "#ee3425"); $("#get_smscode_val").html("获取验证码"); clearInterval(countdown); } count--; } }