AngularJS 驗證碼60秒倒計時功能的實現,angularjs驗證碼

來源:互聯網
上載者:User

AngularJS 驗證碼60秒倒計時功能的實現,angularjs驗證碼

最近在做AngularJS 項目,這是寫的一個60秒倒計時,  angularjs 與jq不同, 不是使用dom節點操作,而是資料操作,寫倒計時,最好是使用$timeout與$interval ,不要使用settimeout與setinterval 。$timeout與$interval 可使綁定資料直接更新。

html

<a href="javascript:" rel="external nofollow" ng-click="sendphonecode(reg_phone)" ng-class="paraclass" ng-bind="paracont">擷取驗證碼</a> 

angularjs

angular.module('controllers', []).controller('registerCtrl', function($scope,$interval){     $scope.paracont = "擷取驗證碼";     $scope.paraclass = "but_null";     $scope.paraevent = true;     var second = 60,       timePromise = undefined;     timePromise = $interval(function(){      if(second<=0){       $interval.cancel(timePromise);       timePromise = undefined;       second = 60;       $scope.paracont = "重發驗證碼";       $scope.paraclass = "but_null";       $scope.paraevent = true;      }else{       $scope.paracont = second + "秒後可重發";       $scope.paraclass = "not but_null";       second--;      }     },1000,100); }); 

以上所述是小編給大家介紹的AngularJS 驗證碼60秒倒計時功能的實現,希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對幫客之家網站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.