本文主要和大家分享js实现获取短信验证码实例,主要以代码的形式和大家分享,希望能帮助到大家。
$(".form-data").delegate(".send","click",function
() {
var phone = $("#tel").val();
if (phone == "") {
alert('请先填写手机号')
$("#tel").css("background-color","#ff2f28");
return false;
}
$(this).hide();
$.ajax({
url: "/sendsms",
type: "get",
dataType: 'json',
data: {phone: phone },
async: false,
success: function (data) {
console.log(data)
if (data.status == 0) {
settime();
} else {
alert(data.msg)
settime();
}
},
error: function () {
alert('网络忙');
settime();
}
});
})
var countdown = 120;
function settime() {
if (countdown == 0) {
$(".time").attr("class","time hide");
$(".time").text("<em>120</em>s");
$(".send").css('display','block');
countdown = 120;
return false;
} else {
$(".time").removeClass('hide');
$(".time").text("重新发送("+ countdown+"s)");
countdown--;
}
setTimeout(function () {
settime();
}, 1000);
}相关推荐:
以上就是js实现获取短信验证码实例的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号