Js: Click to get the verification code countdown effect, js get the verification code countdown Effect

Source: Internet
Author: User

Js: Click to get the verification code countdown effect, js get the verification code countdown Effect

In order to prevent malicious access to verification text messages and email addresses, the website performs a countdown by clicking the get verification code button. To implement this function, one setInterval and one clearInterval can be done without too much code. The instance effect and Code are as follows:

<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <input type = "button" style = "height: 32px; width: 120px; "value =" click to send the verification code "onclick =" sendCode (this) "/> <script type =" text/javascript "> var clock = ''; var nums = 10; var btn; function sendCode (thisBtn) {btn = thisBtn; btn. disabled = true; // do not click btn. value = nums + 'can be retrieved again in seconds'; clock = setInterval (doLoop, 1000); // one-second execution} function doLoop () {nums --; if (nums> 0) {btn. value = nums + 'can be retrieved again in seconds';} else {clearInterval (clock); // clear js timer btn. disabled = false; btn. value = 'send Verification Code click'; nums = 10; // reset time }}</script>

Using setInterval and clearIntervaljs, you can click js to obtain the verification code countdown effect. I hope this will be helpful for your learning.

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.