Angular.js实现获取验证码倒计时60秒按钮的简单方法
前言
本文主要介绍了关于Angular.js实现获取验证码倒计时60秒按钮的相关内容,关于这个功能相信不用多介绍,大家都不陌生,所以下面话不多说了,来一起看看实现的方法吧。
一、controller中代码
angular.module('controllers') .controller('LoginCtrl', function ($scope, $location,$ionicLoading,$rootScope,$interval,$timeout) { $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); }; });
二、html页面中
<button class="yz-btn" ng-click="onClick()" ng-disabled="timer"><span ng-if="showTimer">{{timerCount}}</span>{{text}}</button>
注:
1.class="yz-btn"
为button的样式,可自己修改;
2.ng-disabled="timer"
控制button是否可以点击;
3.ng-if="showTimer"
控制数字显示;
4.ng-click="onClick()"
触发效果,文字text默认“获取验证码”,点击之后为“60s后重新获取”。
三、效果图
1、点击前
2、点击后
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。
相关文章
详解AngularJs中$sce与$sceDelegate上下文转义服务
这篇文章给大家详细介绍了AngularJs提供的严格上下文转义服务$sce与$sceDelegate,文中介绍的很详细,有需要的朋友们可以参考借鉴。2016-09-09AngularJS实践之使用NgModelController进行数据绑定
大家都知道AngularJS中的指令是其尤为复杂的一个部分,但是这也是其比较好玩的地方。这篇文章我们就来说一说如何在我们自定义的指令中,利用ngModel的controller来做双向数据绑定,本文对大家学习AngularJS具有一定的参考借鉴价值,有需要的朋友们可以参考借鉴。2016-10-10Angular8引入百度Echarts进行图表分析的实现代码
这篇文章主要介绍了Angular8引入百度Echarts进行图表分析的实现代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2019-11-11
最新评论