<html> <header></header> <script> var wait=60; var interValObj; function fsend(){ interValObj = window.setInterval(setRemainTime, 1000); ///--啓動計時器,1秒執行一次 document.getElementById("code_button").disabled=true; document.getElementById("code_button").innerText="倒計時 " + wait + " 秒"; } function setRemainTime() { if (wait == 0) { window.clearInterval(interValObj); //中止計時器 document.getElementById("code_button").disabled=false; document.getElementById("code_button").innerText="從新發送驗證碼" ; document.getElementById('code_value').value = ''; //清除驗證碼。若是不清除,過期間後,輸入收到的驗證碼依然有效 wait = 60; } else { wait--; document.getElementById("code_button").innerText="倒計時 " + wait + " 秒"; } } </script> <body> Send Scode <input type="text" id="code_value"/> <button type="button" id="code_button" name="send" onclick="fsend()" >發送驗證碼</button> </body> </html>