<script>
var timeId;
var countdown=60;
$("#sms_code").click(function(){
sendSms();
});
function sendSms()
{
var mobile = $('#loginform-username').val();
if(!(/^1[34578]\d{9}$/.test(mobile))){
var message = '手机号码有误,请重新输入';
$("#message").html(message)
return false;
}
timeId = setInterval(settime,1000);
$.ajax({
type : 'POST',
data : {'mobile':mobile},
url : "你自己url",
//url:'/index.php?r=user/login/getSmsCode',
success : function(data){
if( data.status == 'success' ){
$("#message").html("<span style='color:white;'>" + data.msg + "</span>");
return false;
}else if( data.status == 'fail' ){
$("#message").html(data.msg);
return false;
}
},
});
}
function settime() {
if (countdown == 0) {
$("#sms_code").attr("disabled",false);
$("#sms_code").html("点击发送验证码");
countdown = 60;
clearInterval(timeId);
} else {
$("#sms_code").attr("disabled", true);
$("#sms_code").html("重新发送(" + countdown + ")");
countdown--;
}
}
var timeId;
var countdown=60;
$("#sms_code").click(function(){
sendSms();
});
function sendSms()
{
var mobile = $('#loginform-username').val();
if(!(/^1[34578]\d{9}$/.test(mobile))){
var message = '手机号码有误,请重新输入';
$("#message").html(message)
return false;
}
timeId = setInterval(settime,1000);
$.ajax({
type : 'POST',
data : {'mobile':mobile},
url : "你自己url",
//url:'/index.php?r=user/login/getSmsCode',
success : function(data){
if( data.status == 'success' ){
$("#message").html("<span style='color:white;'>" + data.msg + "</span>");
return false;
}else if( data.status == 'fail' ){
$("#message").html(data.msg);
return false;
}
},
});
}
function settime() {
if (countdown == 0) {
$("#sms_code").attr("disabled",false);
$("#sms_code").html("点击发送验证码");
countdown = 60;
clearInterval(timeId);
} else {
$("#sms_code").attr("disabled", true);
$("#sms_code").html("重新发送(" + countdown + ")");
countdown--;
}
}
</script>
以上便是整体的效果代码