1.js中使用倒計時用setTimeout()
<input type="button" id="sendCode" value="發(fā)送驗證碼" />
<script type="text/javaacript">
// 驗證碼 倒計時60秒
var wait=60;
function time(o) {
if (wait == 0) {
o.removeAttribute("disabled");
o.value="發(fā)送驗證碼";
wait = 60;
} else {
o.setAttribute("disabled", true);
o.value="重新發(fā)送(" + wait + ")";
wait--;
setTimeout(function() {
time(o)
},
1000)
}
}
document.getElementById("sendCode").onclick=function(){time(this);}
</script>