<input type="tel" class="input_yan" name="sms_code" autocomplete="off" id="sms_code" placeholder="請輸入驗證碼" />
<input type="button" class="get_yan_text" value="獲取驗證碼" id="sendCode">
var countdown = 60;
var timer;
function settime(obj) {
if (countdown == 0) {
// obj.removeAttribute("disabled");
$('#sendCode').removeAttr("disabled");
obj.value = "獲取驗證碼";
$("#sendCode").css("color", "rgba(121, 75, 26, 1)");
countdown = 60;
return;
} else {
$('#sendCode').attr("disabled", "disabled");
//obj.setAttribute("disabled", true);
obj.value = countdown + "s重新獲取";
$("#sendCode").css("color", "#CCCCCC");
countdown--;
}
timer = setTimeout(function () {
settime(obj);
}, 1000)
}
$('#sendCode').click(function () {
if (countdown < 60) {
return false;
}
if ($('input[name=phone]').val() == '') {
layer.msg('請輸入手機號碼', {
// icon: 1,
time: 1000 //(默認是3秒)
}, function () {
//do something
});
return false;
}
settime(this);
var _this = this;
var input_phone = $('input[name=phone]').val();
input_phone = input_phone.replace(/\s*/g, "");
var post_data = {
phone: input_phone,
};
$.post(url, post_data ,
function (json2) {
if (json2.code == 200) {
// layer.msg(json.msg, {icon:6});
}
if (json2.code != 200) {
clearTimeout(timer);
$('#sendCode').removeAttr("disabled");
$("#sendCode").css("color", "rgba(121, 75, 26, 1)");
_this.value = "獲取驗證碼";
countdown = 60;
layer.msg(json2.msg, {
// icon: 1,
time: 1000 //(默認是3秒)
}, function () {
//do something
});
}
})
});