<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript"> window.onload=function(){ var send=document.getElementById('send'); times=60; timer=null; send.οnclick=function(){ // 計時開始 timer=setInterval(function(){ times--; if(times<=0){ send.value='發送驗證碼'; clearInterval(timer); times=60; send.disabled=false; //是否可點擊 }else{ send.value=times+'秒後重試'; send.disabled=true; }console.log(times); },1000); } } </script> </head> <body> <input type="button" id="send" value="發送驗證碼"> </body> </html>
按鈕發送驗證碼等待時間效果——定時器setInterval使用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.