js倒计时 重发 效果

时间:2023-03-09 13:10:53
js倒计时 重发 效果
<script type="text/javascript">
window.onload = function() {
var wait = 60; function time(o) {
if (wait == 0) {
o.removeAttribute("disabled");
o.value = "重新获取验邮件";
wait = 60;
} else {
o.setAttribute("disabled", true);
o.value = "重新发送(" + wait + ")";
wait--;
setTimeout(function() {
time(o)
},
1000)
}
}
document.getElementById("btn").onclick = function() {
time(this);
}
// 0.5秒后模拟点击
setTimeout(function() {
// IE
if (document.all) {
document.getElementById("btn").click();
}
// 其它浏览器
else {
var e = document.createEvent("MouseEvents");
e.initEvent("click", true, true);
document.getElementById("btn").dispatchEvent(e);
}
}, 500);
}
</script>
<input type="button" id="btn" value="重新获取验邮件" class="button" />