1.html代码
<input type="text" name="code" id="code" placeholder="请输入验证码"/>
<input type="button" id="btncode" onclick="getcode();" value="获取手机验证码"/>
2.javaScript代码
-
var count=60;
-
var countdown;
-
function getcode(){
-
var phone = $("#phone").val();
-
count = 60;//设置
-
countdown = setInterval(CountDown, 1000);
-
$.post('user-getcode.html',{phone:phone},function(result){
-
if(result['status']==1){
-
$("#code").val(result['msg']);
-
}
-
},'json');
-
-
}
-
function CountDown() {
-
$("#btncode").attr("disabled", true);//让按钮不可点击
-
$("#btncode").val("还剩" + count + " s");
-
if (count == 0) {
-
$("#btncode").removeAttr("disabled");
-
$("#btncode").val("重新发送验证码");
-
clearInterval(countdown);
-
}
-
count--;
-
}
阅读(924) | 评论(0) | 转发(0) |