JavaScript to send SMS verification code to achieve code _JAVASCRIPT skills

Source: Internet
Author: User

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:

<!doctype html>
 
 

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.