关键代码如下:
<input type="button" class="btn btn-warning" id="btn_resend_email" value="发送验证码" />
<script>
var wait = 60;
function towait() {
if (wait == 0) {
$("#btn_resend_email").removeAttr("disabled");
$("#btn_resend_email").attr("value", "发送验证码");
wait = 60;
} else {
$("#btn_resend_email").attr("disabled", true);
$("#btn_resend_email").attr("value", "重新发送(" + wait + "s)");
wait--;
// setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式
setTimeout(function() { // 定时执行
towait();
}, 1000);
}
}
</script>
原文:http://blog.csdn.net/cryhelyxx/article/details/44646121