HTML60秒倒計時

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 
 4 <head>
 5     <meta charset="UTF-8">
 6     <title>60秒倒計時</title>
 7 </head>
 8 
 9 <body>
10     <input type="button" id="btn" value="獲取驗證碼" onclick="sendemail()" />
11 </body>
12 
13 </html>
14 <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
15 <script>
16 var countdown = 5
17 
18 function sendemail() { 19     var obj = $("#btn") 20  settime(obj) 21  console.log('發送郵件') 22 } 23 
24 function settime(obj) { 25     if (countdown == 0) { 26  obj.attr('disabled', false) 27  obj.val("獲取驗證碼") 28  countdown = 5
29         return
30  } else { 31  obj.attr('disabled', true) 32  obj.val("從新發送(" + countdown + ")") 33  countdown--
34  } 35  setTimeout(function() { 36  settime(obj) 37  }, 1000) 38 } 39 </script>
相關文章
相關標籤/搜索