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>