- With Ajax authentication
Original link: http://www.cnblogs.com/steed-zgf/archive/2012/02/03/2336984.html
<!DOCTYPE HTML><Head><Scriptsrc= "Http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></Script><Scripttype= "Text/javascript">varintervalobj;//timer variable, control timevarCount= -; //interval function, 1 second executionvarCurcount;//current number of seconds remainingfunctionSendMessage () {Curcount=count; //Set button effect to start timing $("#btnSendCode"). attr ("Disabled", "true"); $("#btnSendCode"). Val ("Please check the" +Curcount+ "Enter the verification code in seconds"); Intervalobj=Window.setinterval (Setremaintime, +); //start Timer, execute once in 1 seconds //send processing data to the background$.ajax ({type:"POST", //transfer by postDataType:"text", //data format: JSONURL:'login.ashx', //Destination AddressData:"dealtype=" +Dealtype+"&uid=" +UID+ "&code=" +code, Error:function(XMLHttpRequest, Textstatus, Errorthrown) {}, Success:function(msg) {}});}//Timer handler functionfunctionSetremaintime () {if(Curcount== 0) {window.clearinterval (intervalobj);//Stop Timer $("#btnSendCode"). Removeattr ("Disabled");//Enable button $("#btnSendCode"). Val ("Resend Verification Code"); } Else{Curcount--; $("#btnSendCode"). Val ("Please check the" +Curcount+ "Enter the verification code in seconds"); } }</Script></Head><Body> <inputID= "Btnsendcode"type= "button"value= "Send Verification Code"onclick= "SendMessage ()" /></P></Body></HTML>
- With no Ajax
<!DOCTYPE HTML><HTML><Head><Scriptsrc= "Http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></Script><Scripttype= "Text/javascript"> varCountdown= -; functionsettime (obj) {if(Countdown== 0) {Obj.removeattribute ("Disabled"); Obj.value="get a free verification code"; Countdown= -; return; } Else{Obj.setattribute ("Disabled", true); Obj.value="Resend (" +Countdown+ ")"; Countdown--; } setTimeout (function() {settime (obj)}, +) } </Script><Body> <inputtype= "button"ID= "BTN"value= "Get a free verification Code"onclick= "SetTime (this)" /> </Body></HTML>
Front-end Common library-send SMS Verification code countdown 60 seconds