JS 60秒后重发送验证码

  1. <!DOCTYPE html>  
  2. <html lang="en">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>Document</title>  
  6. </head>  
  7. <body>  
  8.     <button id="getPhoneCode"></button>  
  9.     <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>  
  10.     <script>  
  11.         function settime($obj,time){  
  12.             if(time==0){  
  13.                 $obj.attr("disabled",false);  
  14.                 $obj.css("background","#f38401").css("cursor","pointer");  
  15.                 $obj.text("获取手机验证码");  
  16.                 return;  
  17.             }else{  
  18.                 $obj.attr("disabled",true);  
  19.                 $obj.css("background","#ccc").css("cursor","noe-allowed");  
  20.                 $obj.text("重新发送("+time+")");  
  21.                 time--;  
  22.             }  
  23.             setTimeout(function(){settime($obj,time)},1000);  
  24.         }  
  25.         settime($("#getPhoneCode"),60);  
  26.     </script>  
  27. </body>  
  28. </html
原文地址:https://www.cnblogs.com/qq735675958/p/7421843.html