Home Web Front-end JS Tutorial Use Angular.js to get the verification code countdown 60 seconds button method

Use Angular.js to get the verification code countdown 60 seconds button method

Jan 09, 2018 pm 05:08 PM
angular.js javascript Countdown

When I was working on a project recently, I encountered the need for a verification code countdown. I found that this function is quite practical, so I thought of summarizing it. This article mainly introduces how to use Angular.js to implement the verification code countdown button. The simple method, friends in need can refer to it, let’s take a look below.

Preface

This article mainly introduces the relevant content about the Angular.js implementation of the 60-second countdown button for obtaining the verification code. I believe there is no need to introduce more about this function. Everyone is familiar with it, so I will not say anything below. Enough said, let’s take a look at how to implement it.

1. Code in controller

angular.module('controllers')
 .controller('LoginCtrl', function ($scope, $location,$ionicLoading,$rootScope,$interval,$timeout) {
 $scope.timer = false;
 $scope.timeout = 60000;
 $scope.timerCount = $scope.timeout / 1000;
 $scope.text = "获取验证码";
 $scope.onClick = function(){
  $scope.showTimer = true;
  $scope.timer = true;
  $scope.text = "秒后重新获取";
  var counter = $interval(function(){
  $scope.timerCount = $scope.timerCount - 1;
  }, 1000);
  $timeout(function(){
  $scope.text = "获取验证码";
  $scope.timer = false;
  $interval.cancel(counter);
  $scope.showTimer = false;
  $scope.timerCount = $scope.timeout / 1000;
  }, $scope.timeout);
 };
 });
Copy after login

2.

<button class="yz-btn" ng-click="onClick()" ng-disabled="timer"><span ng-if="showTimer">{{timerCount}}</span>{{text}}</button>
Copy after login

in html page Note:

1.class="yz-btn" It is the style of the button, which can be modified by yourself;

2.ng-disabled="timer" controls whether the button can be clicked;

3.ng-if="showTimer "Control the digital display;

4. ng-click="onClick()" triggers the effect. The text defaults to "Get verification code", and after clicking it is "Get again after 60s".

3. Effect drawing

1. Before clicking


##2. After clicking

Related recommendations:

Javascript 60-second countdown to get verification code

Example analysis of 60-second countdown to get verification code in WeChat applet

Modify the PHP program that obtains the verification code image to the local_PHP tutorial

The above is the detailed content of Use Angular.js to get the verification code countdown 60 seconds button method. 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 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

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 use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

How to use JavaScript and WebSocket to implement a real-time online ordering system

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecasting system

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

Simple JavaScript Tutorial: How to Get HTTP Status Code

How to cancel the 10-second countdown on booting up Win10? Three ways to cancel the countdown on booting up Win10 How to cancel the 10-second countdown on booting up Win10? Three ways to cancel the countdown on booting up Win10 Feb 29, 2024 pm 07:25 PM

How to cancel the 10-second countdown on booting up Win10? Three ways to cancel the countdown on booting up Win10

How to get HTTP status code in JavaScript the easy way How to get HTTP status code in JavaScript the easy way Jan 05, 2024 pm 01:37 PM

How to get HTTP status code in JavaScript the easy way

See all articles