html代码
<div class="control-group">
<label for="inputPassword" class="control-label">验证码:</label>
<div class="controls">
<input type="text" id="code" name="code" placeholder="验证码" class="input-xfat input-xlarge" style="width:120px">
<button type="button" class="btn-xlarge" id="dyMobileButton" style="height: 37px;">发送验证码</button>
</div>
</div>
js代码
//发送ajax 获取短信验证码
$.post("{:url('Register/sendCode')}",{phone:phone},function(res){
console.log(res);
var time = 60;//设置时间
var timer = setInterval(function(){
time--;
$('#dyMobileButton').attr('disabled',true);
$('#dyMobileButton').text("重新发送("+time+"s)");
if(time==0){
clearInterval(timer);
$('#dyMobileButton').text("发送验证码").removeAttr('disabled');
}
},1000);
},'json')