js--implementation of SMS Verification code Countdown function (no verification code, only countdown)

Source: Internet
Author: User

1. Function description

When the user wants to get the verification code, click Free to get the verification code, and then start the countdown, the Countdown period button text for the remaining time x seconds, and not press the status, after the countdown ended, the button changed to click Resend.

2. Analysis

The timer must be used. Click on the button to make a judgment within the timer. Countdown 60 seconds, to 0 end.

3, the Code implementation:

  Key Introduction : The timer before the next countdown, be sure to clear, so that the next timer countdown is normal.

<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "UTF-8">        <title></title>        <styletype= "Text/css">            *{margin:0;padding:0;}. Send{width:250px;margin:0 Auto;            }. Send Input{Display:Block;width:200px;Font:16px/30px "Microsoft Ya Hei";Outline:None;Border:None;            }. Send button{Height:30px;Border:None;Outline:None;Font:16px/30px "Microsoft Ya Hei";text-align:Center;            }        </style>        <Scripttype= "Text/javascript">window.onload=function(){                varButton=document.getElementsByTagName ("Button")[0]; Button.innertext="get a free verification code"; varTimer=NULL; Button.onclick=function() {clearinterval (timer);//This is a very important sentence .                    var Time=6; var that= This;//HabitsTimer=SetInterval (function() {Console.log (time); if( time<=0) {That.innertext=""; That.innertext="Click Resend"; That.disabled=false; }Else{that.disabled=true; That.innertext=""; That.innertext="Time Remaining"+(Time)+"seconds"; time--; }                    }, +); }            }        </Script>    </Head>    <Body>        <DivID= "Send">            <inputtype= "text"name= "in"ID= "in"value="" /><Button></Button>        </Div>    </Body></HTML>

js--implementation of SMS Verification code Countdown function (no verification code, only countdown)

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.