大家好,我在注冊會員時,所有輸入框都輸入正確,唯獨驗證碼輸入錯誤,在驗證碼輸入錯誤的同時,驗證碼沒有自動更新,請兄弟們指點一下,如下圖。
script如下
$(document).on("click", ' #send-btn', function () {
const email = $('#email').val();
const sendBtn = $(this);
sendBtn.prop('disabled', true);
if(!email){
layer.tips('請填寫注冊郵箱!', '#email', {
tips: [3, 'red'],time: 6000
});
return false;
}
if(!isEmail(email)){
layer.tips('郵箱格式錯誤,請重新填寫!', '#email', {
tips: [3, 'red'],time: 6000
});
return false;
}
$.ajax({
type: 'POST',
url: "{U('api/index/send_email_code')}",
data: {
email: email
},
success: function (response) {
// 發送郵件成功后,啟動倒計時
let seconds = 60;
// 啟動倒計時
const countdownInterval = setInterval(() => {
seconds--;
if (seconds <= 0) {
clearInterval(countdownInterval);
sendBtn.html('發送郵件驗證碼');
sendBtn.prop('disabled', false);
} else {
sendBtn.html('已發送, ' + seconds + '秒');
}
}, 1000);
},
error: function (data) {
layer.msg(data.responseJSON.msg, {icon: 2, offset: '16px', anim: 'slideDown', time: 5000});
sendBtn.prop('disabled', false);
}
});
});
function tijiao(obj, url){
$.ajax({
type: 'POST',
url: url,
data: $(obj).serialize(),
dataType: "json",
success: function (msg) {
if(msg.status == 1){
layer.msg(msg.message, {icon:1,time: 2000}, function(){
window.location.href = msg.url;
});
}else{
layer.msg(msg.message, {icon:2,time: 2500});
}
}
})
return false;
}