1. Function description
When the user wants to get the verification code, click Free to get the verification code, and then start the countdown, the Countdown period button text for the remaining time x seconds, and not press the status, after the countdown ended, the button changed to click Resend.
2. Analysis
The timer must be used. Click on the button to make a judgment within the timer. Countdown 60 seconds, to 0 end.
3, the Code implementation:
Key Introduction : The timer before the next countdown, be sure to clear, so that the next timer countdown is normal.
<!DOCTYPE HTML><HTML> <Head> <MetaCharSet= "UTF-8"> <title></title> <styletype= "Text/css"> *{margin:0;padding:0;}. Send{width:250px;margin:0 Auto; }. Send Input{Display:Block;width:200px;Font:16px/30px "Microsoft Ya Hei";Outline:None;Border:None; }. Send button{Height:30px;Border:None;Outline:None;Font:16px/30px "Microsoft Ya Hei";text-align:Center; } </style> <Scripttype= "Text/javascript">window.onload=function(){ varButton=document.getElementsByTagName ("Button")[0]; Button.innertext="get a free verification code"; varTimer=NULL; Button.onclick=function() {clearinterval (timer);//This is a very important sentence . var Time=6; var that= This;//HabitsTimer=SetInterval (function() {Console.log (time); if( time<=0) {That.innertext=""; That.innertext="Click Resend"; That.disabled=false; }Else{that.disabled=true; That.innertext=""; That.innertext="Time Remaining"+(Time)+"seconds"; time--; } }, +); } } </Script> </Head> <Body> <DivID= "Send"> <inputtype= "text"name= "in"ID= "in"value="" /><Button></Button> </Div> </Body></HTML>
js--implementation of SMS Verification code Countdown function (no verification code, only countdown)