Angular.js實現(xiàn)獲取驗證碼倒計時60秒按鈕的簡單方法
前言
本文主要介紹了關于Angular.js實現(xiàn)獲取驗證碼倒計時60秒按鈕的相關內容,關于這個功能相信不用多介紹,大家都不陌生,所以下面話不多說了,來一起看看實現(xiàn)的方法吧。
一、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);
};
});
二、html頁面中
<button class="yz-btn" ng-click="onClick()" ng-disabled="timer"><span ng-if="showTimer">{{timerCount}}</span>{{text}}</button>
注:
1.class="yz-btn"為button的樣式,可自己修改;
2.ng-disabled="timer"控制button是否可以點擊;
3.ng-if="showTimer"控制數(shù)字顯示;
4.ng-click="onClick()"觸發(fā)效果,文字text默認“獲取驗證碼”,點擊之后為“60s后重新獲取”。
三、效果圖
1、點擊前

2、點擊后

總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關文章
詳解使用angular-cli發(fā)布i18n多國語言Angular應用
這篇文章主要介紹了詳解使用angular-cli發(fā)布i18n多國語言Angular應用,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05
詳解Angular系列之變化檢測(Change Detection)
這篇文章主要介紹了詳解Angular系列之變化檢測(Change Detection),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-02-02
Angular使用ControlValueAccessor創(chuàng)建自定義表單控件
這篇文章主要介紹了Angular使用ControlValueAccessor創(chuàng)建自定義表單控件,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-03-03
AngularJS框架的ng-app指令與自動加載實現(xiàn)方法分析
這篇文章主要介紹了AngularJS框架的ng-app指令與自動加載實現(xiàn)方法,結合實例形式分析了ng-app指令的功能及自動加載機制的實現(xiàn)技巧,需要的朋友可以參考下2017-01-01
詳解AngularJS1.x學習directive 中‘& ’‘=’ ‘@’符號的區(qū)別使用
這篇文章主要介紹了詳解AngularJS1.x學習directive 中‘& ’‘=’ ‘@’符號的區(qū)別使用,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-08-08

