var $getCode = $(".resend-btn");
var wait = 60;
function time(btn) {
if (wait === 0) {
btn.removeAttr("disabled");
btn.html("重新发送");
wait = 60;
} else {
btn.attr("disabled", true);
btn.html(wait + "秒后才能再次发送");
wait--;
setTimeout(function () {
time(btn);
}, 1000);
}
}
$getCode.on("click", function () {
time($(this));
var wait = 60;
function time(btn) {
if (wait === 0) {
btn.removeAttr("disabled");
btn.html("重新发送");
wait = 60;
} else {
btn.attr("disabled", true);
btn.html(wait + "秒后才能再次发送");
wait--;
setTimeout(function () {
time(btn);
}, 1000);
}
}
$getCode.on("click", function () {
time($(this));
});
resend-btn为点击触发的class属性。
本文介绍了一种使用JavaScript实现的倒计时按钮功能,当按钮被点击后将开始倒计时,在倒计时过程中按钮会被禁用并显示剩余时间。
35

被折叠的 条评论
为什么被折叠?



