html部分
<input class="code-input" type="tel" maxlength="6" placeholder="输入验证码" />
<button id="codeBtn" disabled="disabled">获取验证码</button>
js部分
//发送验证码倒计时
var countdown = 10;
var obj = $("#codeBtn");
$('#codeBtn').on('click', function() {
settime(obj);
console.log($("#mob").val())
$.ajax({
url: "http://dbs.app.douboshi.cn/App/Christmas/Index/sendSms", //请求的url地址
dataType: "json", //返回格式为json
async: true, //请求是否异步,默认为异步,这也是ajax重要特性
data: {
"phone": $("#mob").val()
}, //参数值
type: "post", //请求方式
success: function(req) {
//请求成功时处理
if(req.success == true) {
$('.error-small').html(req.msg);
$(".error-small").show();
$(".error-small").fadeOut(3000)
} else {
$('.error-small').html(req.msg);
$(".error-small").show();
$(".error-small").fadeOut(3000)
}
},
error: function() {
//请求出错处理
}
});
})
function settime(obj) {
if(countdown == 0) {
obj.attr('disabled', false);
//obj.removeattr("disabled");
obj.html("获取验证码");
countdown = 10;
return;
} else {
obj.attr('disabled', true);
obj.removeClass('.text-red')
obj.html(countdown);
countdown--;
}
setTimeout(function() {
settime(obj)
}, 1000)
}```