Simple implementation method of verification code countdown for mobile phone registration

Source: Internet
Author: User
Tags sessionstorage
This article mainly for you to share a mobile phone registration to send a verification code countdown to a simple example. Has a very good reference value, along with the small series to see it, hope to help you, hope to help everyone.

As shown below:

() Here is the click of input to send the verification code <input type= "number" class= "input" name= "mobile" placeholder= "mobile" style= "Border:none" < Input class= "Hui_kuang" style= "width:30%;text-align:center;height:42px" onclick= "settime (This)" value= ' Get Verification code ' > <script>//page initialization gets the countdown number (to avoid the countdown when the user refreshes the browser resulting in a time-out of zero) var $getCodeInput = $ (". Hui_kuang"); var sessioncountdown = Sessionstorage.getitem ("Countdown");  if (!sessioncountdown) {$ (". Hui_kuang"). Val ("Get Verification Code")} else {$ (". Hui_kuang"). Val ("Resend (" + Sessioncountdown + ")"); Setcode ($getCodeInput, Sessioncountdown);  }//Get the CAPTCHA function settime () {var remobile = $ ("#registForm input[name= ' mobile ']"). Val ();  if (!remobile) {alert ("Please enter mobile number") return; } if (! (  /^1[3|4|5|8][0-9]\d{4,8}$/.test (Remobile)) {alert ("Please enter a valid mobile number") return;  } else {Setcode ($getCodeInput, 60); }}//Send verification code Countdown function Setcode ($getCodeInput, Countdown) {if (countdown = = 0) {$getCodeInput. attr (' disabled ', false)   ;//$getCodeInput. RemoveAttribute ("Disabled"); $getCodeInput. VAL ("Get Verification Code");   Sessionstorage.removeitem ("Countdown");  Return   } else {$getCodeInput. attr (' disabled ', true);   $getCodeInput. Val ("Resend (" + Countdown + ")");  countdown--;  } sessionstorage.setitem ("Countdown", Countdown);  Window.settimeout (function () {Setcode ($getCodeInput, Countdown); }, 1000); }</script>
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.