国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

ionic+AngularJs實現獲取驗證碼倒計時按鈕

2019-11-19 16:45:56
字體:
來源:轉載
供稿:網友

按鈕功能為:點擊“獲取驗證碼”――按鈕不可用-設置倒計時-60秒后重新獲取。

主要實現原理:點擊后,設置一個$interval,每一秒更改一次剩余時間,并依賴Angular數據綁定實時顯示在頁面中。設置一個$timeout,60秒后將按鈕初始化到可用狀態。

實現代碼:

(1)js代碼,設置成一個directive以便多次調用。

angular.module('winwin').directive('timerbutton', function($timeout, $interval){  return {    restrict: 'AE',    scope: {      showTimer: '=',      timeout: '='    },    link: function(scope, element, attrs){      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);      }    },    template: '<button on-tap="onClick()" class="button button-calm xgmm-btn" ng-disabled="timer"><span ng-if="showTimer">{{ timerCount }}</span>{{text}}</button>'  };});

(2)html代碼

 <timerbutton show-timer="false">獲取驗證碼</timerbutton>

實現效果:

(1)點擊之前

  

(2)點擊之后

   

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 怀远县| 武宣县| 尼勒克县| 淮滨县| 德州市| 绥德县| 平利县| 大庆市| 莎车县| 合川市| 科技| 四子王旗| 惠安县| 邛崃市| 潼南县| 武城县| 板桥市| 昌都县| 望城县| 大兴区| 崇左市| 阳曲县| 乃东县| 潮州市| 阿克陶县| 微山县| 霍城县| 稷山县| 尉氏县| 裕民县| 集贤县| 新绛县| 井陉县| 新和县| 克拉玛依市| 新余市| 尚志市| 汝城县| 洛川县| 威海市| 象山县|