Programme I
1<div class= "div user-input" >2<input type= "number" class= "code" name= "Verify" placeholder= "Please enter phone verification code" required maxlength= "6" >3<input type= "button" class= "Obtain Generate_code" value= "Get Verification Code" >4</div>5<script type= "Text/javascript" >6$(function(){ 7$ (". Generate_code"). Click (function(){ 8 varDisabled = $ (". Generate_code"). attr ("Disabled"); 9 if(disabled) {Ten return false; One } A if($ ("#mobile"). val () = = "" | | IsNaN ($ ("#mobile"). Val ()) | | $ ("#mobile"). Val (). length! = 11 ){ -Alert ("Please fill in the correct phone number!") "); - return false; the } - $.ajax ({ -Asyncfalse, -Type: "GET", +URL: "{: U (' user/sms ')}", -Data: {mobile:$ ("#mobile")). Val ()}, +DataType: "JSON", AAsyncfalse, atSuccessfunction(data) { - console.log (data); - settime (); - }, -Errorfunction(err) { - Console.log (ERR); in } - }); to }); + varCountdown=60; - var_generate_code = $ (". Generate_code"); the functionsettime () { * if(Countdown = = 0) { $_generate_code.attr ("Disabled",false); Panax Notoginseng_generate_code.val ("Get Verification Code"); -Countdown = 60; the return false; +}Else { A$ (". Generate_code"). attr ("Disabled",true); the_generate_code.val ("Resend (" + Countdown + ")"); +countdown--; - } $SetTimeout (function() { $ settime (); -},1000); - } the }) - Wuyi</script>
Programme II
<div class= "div user-input" > <input type= "number" class= "code" placeholder= "Please enter phone verification code" required maxlength= "6" & Gt <input type= "button" class= "Obtain Generate_code" value= "Get Verification Code" onclick= "SetTime (this);" > </div> <script type= "Text/javascript" >//CountdownvarCountdown=60; functionSetTime (val) {if(Countdown = = 0) {Val.removeattribute ("Disabled"); Val.value= "Get Verification Code"; Countdown= 60; return false; } Else{Val.setattribute ("Disabled",true); Val.value= "Resend (" + Countdown + ")"; Countdown--; } setTimeout (function() {settime (val); },1000); } </script>
< original address http://blog.csdn.net/hj7jay/article/details/51433828
The implementation of JS to get the verification code countdown of mobile phone