This paper first analyzes the principle of mobile phone to send verification code, and then to JavaScript to send SMS verification code to achieve, the specific ideas are as follows:
Implementation click the "Send Verification Code" button, the button appears in turn, "59 seconds to retry", "58 seconds to try again" ... Until the countdown to 0 seconds to restore the display as "Send verification code." 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 0 o'clock clear the timer, the button reverts to "Send verification code", otherwise displayed as "X seconds to try again"
Effect Chart:
Implementation code:
Note the point:
When setting the button is disabled,send.disabled=true; send.disabled=false;
true and false cannot be quoted!true and false without quotes!true and false without quotes! Otherwise the value is always true.
Also available send.setattribute (' disabled ', ' disabled ');
or send.removeattribute (' disabled ');
The above is for everyone to share the JavaScript send SMS Verification code All code, I hope to help you learn.