Send SMS Verification Code
After clicking the "Send Verification Code" button, the button appears as "Retry after 59 seconds", "Retry after 58 seconds" ... Revert to "Send verification code" until the countdown to 0 seconds is displayed. The button is disabled during the countdown.
First step, Get button, bind event, set timer variable and timing variable
The second step, add the timer, every 1 seconds time minus 1, until when the timer is less than or equal to 0 o'clock to clear the timer, the button reverts to "Send verification code", otherwise displayed as "x seconds after Retry"
<!doctype html><Htmllang="EN" ><Head><Metacharset="UTF-8" ><Title>document</Title><ScriptType="Text/javascript" >Window.onload=function(){var Send=document.getelementbyid (' Send '), times=Timer=,Null send.onclick=function(){Timing startsvar that =ThisThis.disabled=True Timer = SetInterval (function() {times--; That.value = times +"Retry after second";if (Times <=0) {that.disabled =false; that.value = "Send verification code"; Clearinterval (timer); times = 60; } //console.log (times);},1000); }} </script></ head><body> <input type= "button" id= "send" value=" Send verification code "></ body></HTML>
1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- Ten
- one
-
- 2
- (
- )
- +
- +
- /
- 0
-
- +
-
- all
- +
- +
- +
- -
- 29
-
-
- +
- +
设置按钮是否为禁用时,send.disabled=true; send.disabled=false;true和false不能加引号!true和false不能加引号!true和false不能加引号!否则值永远为真。 也可用send.setAttribute(‘disabled‘,‘disabled‘);或send.removeAttribute(‘disabled‘);
Reprint: http://blog.csdn.net/i10630226/article/details/49531083
Ultra-Practical JavaScript snippet ITEM4--Send SMS Verification code