<script>
var is_send = true;
var tim = setInterval(function () {
$("#time_left").val('' + time_info + 's');
time_info--;
is_send = false;
if (time_info == 0) {
clearInterval(tim);
$("#time_left").val('验证码')
is_send = true;
}
}, 1000)
}
function send_phone() {
if (is_send) {
//调用发送
//手机号的验证
var phone = $("#phone").val();
var myreg = /^1[34578]{1}\d{9}$/;
if (!myreg.test(phone)) {
alert("手机号码格式错误!");
} else {
yanzhengma();
}
//验证码提交到数据库
$.ajax({
type: 'post',
url: '/api/send_mess',
data: {phone: phone},
dataType: 'json',
success: function (data) {
if (data.code == 200) {
alert(data.msg)
// layer.msg(data.msg);
setTimeout(sleepone, 1500);
} else {
alert(data.msg);
}
},
error: function (data) {
// console.log('手机验证错误');
},
});
}
}
</script>
var is_send = true;
var time_info = 60
//验证码倒计时
function yanzhengma() {var tim = setInterval(function () {
$("#time_left").val('' + time_info + 's');
time_info--;
is_send = false;
if (time_info == 0) {
clearInterval(tim);
$("#time_left").val('验证码')
is_send = true;
}
}, 1000)
}
function send_phone() {
if (is_send) {
//调用发送
//手机号的验证
var phone = $("#phone").val();
var myreg = /^1[34578]{1}\d{9}$/;
if (!myreg.test(phone)) {
alert("手机号码格式错误!");
} else {
yanzhengma();
}
//验证码提交到数据库
$.ajax({
type: 'post',
url: '/api/send_mess',
data: {phone: phone},
dataType: 'json',
success: function (data) {
if (data.code == 200) {
alert(data.msg)
// layer.msg(data.msg);
setTimeout(sleepone, 1500);
} else {
alert(data.msg);
}
},
error: function (data) {
// console.log('手机验证错误');
},
});
}
}
</script>