AngularJS 验证码60秒倒计时功能的实现
最近在做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秒倒计时功能的实现,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
相关文章
AngularJS ng-bind-html 指令详解及实例代码
本文主要是对AngularJS ng-bind-html 指令知识的详细讲解,并附代码实例,有需要的小伙伴可以参考下2016-07-07AngularJS使用自定义指令替代ng-repeat的方法
这篇文章主要介绍了另一种即具有与ng-repeat一样处理大量数据的绑定的功能,又具有超高性能的自定义方法,有需要的小伙伴们可以参考借鉴,下面来一起看看吧。2016-09-09解决Angular.js中使用Swiper插件不能滑动的问题
下面小编就为大家分享一篇解决Angular.js中使用Swiper插件不能滑动的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2018-02-02详解Angular 中 ngOnInit 和 constructor 使用场景
最初学习Angular的时候总是搞不清楚ngOnInit和constructor的区别,现在我们来稍微理一下两者之间的区别。2017-06-06
最新评论