第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ionic+AngularJs實現(xiàn)獲取驗證碼倒計時按鈕?

ionic+AngularJs實現(xiàn)獲取驗證碼倒計時按鈕?

慕哥6287543 2018-09-04 14:10:45
ionic+AngularJs實現(xiàn)獲取驗證碼倒計時按鈕
查看完整描述

1 回答

?
MM們

TA貢獻1886條經(jīng)驗 獲得超2個贊

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

 

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

 

實現(xiàn)代碼:

 

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

     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>    

實現(xiàn)效果:

 

(1)點擊之前

 

  

 

(2)點擊之后

 

   


查看完整回答
反對 回復(fù) 2018-09-26
  • 1 回答
  • 0 關(guān)注
  • 1366 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號