ionic+AngularJs實(shí)現(xiàn)獲取驗(yàn)證碼倒計(jì)時(shí)按鈕
按鈕功能為:點(diǎn)擊“獲取驗(yàn)證碼”——按鈕不可用-設(shè)置倒計(jì)時(shí)-60秒后重新獲取。
主要實(shí)現(xiàn)原理:點(diǎn)擊后,設(shè)置一個(gè)$interval,每一秒更改一次剩余時(shí)間,并依賴Angular數(shù)據(jù)綁定實(shí)時(shí)顯示在頁面中。設(shè)置一個(gè)$timeout,60秒后將按鈕初始化到可用狀態(tài)。
實(shí)現(xiàn)代碼:
(1)js代碼,設(shè)置成一個(gè)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 = "獲取驗(yàn)證碼";
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 = "獲取驗(yàn)證碼";
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">獲取驗(yàn)證碼</timerbutton>
實(shí)現(xiàn)效果:
(1)點(diǎn)擊之前

(2)點(diǎn)擊之后
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- JS 實(shí)現(xiàn)獲取驗(yàn)證碼 倒計(jì)時(shí)功能
- JS+HTML5實(shí)現(xiàn)獲取手機(jī)驗(yàn)證碼倒計(jì)時(shí)按鈕
- Angular.js實(shí)現(xiàn)獲取驗(yàn)證碼倒計(jì)時(shí)60秒按鈕的簡單方法
- JS獲取短信驗(yàn)證碼倒計(jì)時(shí)的實(shí)現(xiàn)代碼
- js實(shí)現(xiàn)簡單的獲取驗(yàn)證碼按鈕效果
- JavaScript獲取短信驗(yàn)證碼(周期性)
- JS實(shí)現(xiàn)用戶注冊時(shí)獲取短信驗(yàn)證碼和倒計(jì)時(shí)功能
- JS/jQ實(shí)現(xiàn)免費(fèi)獲取手機(jī)驗(yàn)證碼倒計(jì)時(shí)效果
- js實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼倒計(jì)時(shí)效果
- JavaScript實(shí)現(xiàn)10秒后再次獲取驗(yàn)證碼
相關(guān)文章
AngularJs點(diǎn)擊狀態(tài)值改變背景色的實(shí)例
下面小編就為大家分享一篇AngularJs點(diǎn)擊狀態(tài)值改變背景色的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-12-12
Angularjs 雙向綁定時(shí)字符串的轉(zhuǎn)換成數(shù)字類型的問題
這篇文章主要介紹了Angular js雙向綁定時(shí)字符串的轉(zhuǎn)換成數(shù)字類型的問題,需要的朋友可以參考下2017-06-06
AngularJS API之copy深拷貝詳解及實(shí)例
這篇文章主要介紹了AngularJS API之copy深拷貝詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2016-09-09
AngularJS2 與 D3.js集成實(shí)現(xiàn)自定義可視化的方法
本篇文章主要介紹了ANGULAR2 與 D3.js集成實(shí)現(xiàn)自定義可視化的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-12-12
angular2組件中定時(shí)刷新并清除定時(shí)器的實(shí)例講解
今天小編就為大家分享一篇angular2組件中定時(shí)刷新并清除定時(shí)器的實(shí)例講解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08

