HTML:
<button id="getCode" type="button" class="code-item pull-right">短信验证码</button>
JS:
//"获取短信验证码"
$('#getCode').unbind('click').click(function (event){
event.preventDefault();
time(this);
});
var wait=60;
function time(o) {
if (wait == 0) {
o.removeAttribute("disabled");
o.innerHTML="获取动态码";
wait = 60;
} else {
o.setAttribute("disabled", true);
o.innerHTML="重新发送(" + wait + ")";
wait--;
setTimeout(function() { time(o) }, 1000)
}
}
本文介绍了一种实现短信验证码倒计时功能的方法。通过HTML和JavaScript代码展示了如何禁用按钮并显示剩余时间,直至倒计时结束。具体包括设置按钮初始状态、点击事件处理及递减等待时间等关键步骤。
373

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



