Home Web Front-end JS Tutorial JS implements SMS verification code

JS implements SMS verification code

Aug 11, 2017 am 10:16 AM
javascript Short message verify

To implement the SMS verification code interface, you must first have a text box with a button next to it. When clicked, the countdown starts. Next, through this article, I will share with you the js implementation of a simple SMS verification code interface. Friends who are interested can refer to it

1. To implement the SMS verification code interface, first there must be a text box with a button next to it. When clicked, Start countdown.

2. First create a text box and button, set the corresponding id for the button, and then obtain the button element through the id in js and perform operations on it. At the same time, the countdown time and timer variables should be set so that after clicking the send button, it is impossible to continue clicking the button to resend before the countdown ends.

3. After the countdown is over, clear the timer and change the text to "Resend Verification Code" to restore the ability to operate the button. At the same time, restart the countdown from 5 seconds so that you can click it again. Countdown.


<head> 
  <meta charset="UTF-8"> 
  <title>js发送短信验证码</title> 
</head> 
<body> 
  <input type="text"/><button id="bt01">发送验证码</button> 
</body> 
<script type="text/javascript"> 
  var bt01 = document.getElementById("bt01"); 
  bt01.onclick = function() { 
    bt01.disabled = true;  //当点击后倒计时时候不能点击此按钮 
    var time = 5;  //倒计时5秒 
    var timer = setInterval(fun1, 1000);  //设置定时器 
    function fun1() { 
      time--; 
      if(time>=0) { 
        bt01.innerHTML = time + "s后重新发送"; 
      }else{ 
        bt01.innerHTML = "重新发送验证码"; 
        bt01.disabled = false;  //倒计时结束能够重新点击发送的按钮 
        clearTimeout(timer);  //清除定时器 
        time = 5;  //设置循环重新开始条件 
      } 
    } 
  } 
</script>
Copy after login

The above is the detailed content of JS implements SMS verification code. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to verify signature in PDF How to verify signature in PDF Feb 18, 2024 pm 05:33 PM

How to verify signature in PDF

How to set up text message blocking on iPhone How to set up text message blocking on iPhone Feb 24, 2024 pm 01:48 PM

How to set up text message blocking on iPhone

Detailed method to unblock using WeChat friend-assisted verification Detailed method to unblock using WeChat friend-assisted verification Mar 25, 2024 pm 01:26 PM

Detailed method to unblock using WeChat friend-assisted verification

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to implement an online speech recognition system using WebSocket and JavaScript

New features in PHP 8: Added verification and signing New features in PHP 8: Added verification and signing Mar 27, 2024 am 08:21 AM

New features in PHP 8: Added verification and signing

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to implement an online reservation system using WebSocket and JavaScript

How to solve the problem of steam login stuck in mobile token verification? How to solve the problem of steam login stuck in mobile token verification? Mar 14, 2024 pm 07:35 PM

How to solve the problem of steam login stuck in mobile token verification?

See all articles