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)擊之后
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(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秒按鈕的簡(jiǎn)單方法
- JS獲取短信驗(yàn)證碼倒計(jì)時(shí)的實(shí)現(xiàn)代碼
- js實(shí)現(xiàn)簡(jiǎn)單的獲取驗(yàn)證碼按鈕效果
- JavaScript獲取短信驗(yàn)證碼(周期性)
- JS實(shí)現(xiàn)用戶注冊(cè)時(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實(shí)現(xiàn)的根據(jù)數(shù)量與單價(jià)計(jì)算總價(jià)功能示例
這篇文章主要介紹了AngularJS實(shí)現(xiàn)的根據(jù)數(shù)量與單價(jià)計(jì)算總價(jià)功能,涉及AngularJS事件響應(yīng)與數(shù)值運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2017-12-12
Angluar+zorro實(shí)現(xiàn)無限級(jí)菜單
這篇文章主要為大家詳細(xì)介紹了Angluar+zorro實(shí)現(xiàn)無限級(jí)菜單,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
angular 實(shí)現(xiàn)下拉列表組件的示例代碼
這篇文章主要介紹了angular 實(shí)現(xiàn)下拉列表組件的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03
AngularJs動(dòng)態(tài)加載模塊和依賴注入詳解
這篇文章主要為大家介紹了AngularJs動(dòng)態(tài)加載模塊和依賴注入,感興趣的小伙伴們可以參考一下2016-01-01

