AngularJS 实现点击按钮获取验证码功能实例代码

所属分类: 网络编程 / JavaScript 阅读数: 807
收藏 0 赞 0 分享

 html :样式采用了sui框架的样式,请自行引入查看,AngularJS,自己引入,

<div ng-controller="forGetPassword" ng-app="routingDemoApp">
  <form novalidate name="forget">
    <header class="bar bar-nav">
      <a href="javascript:history.go(-1);" rel="external nofollow" class="ui-header-btn ui-header-btn-sm"></a>
      <h1 class='title'>忘记密码</h1>
    </header>
    <div class="gorgetpassowrd">
      <ul>
        <li>
          <input type="number" placeholder="请输入您的手机号码" required ng-model="mobile" name="mobile" ng-pattern="/^1[3|4|5|7|8]{1}[0-9]{9}$/">
        </li>
        <div ng-show="forget.mobile.$dirty && !forget.mobile.invalid">
          <p class="textinfo" ng-show="forget.mobile.$error.required">手机号码必填</p>
          <p class="textinfo" ng-show="forget.mobile.$error.pattern">手机号码格式不正确</p>
        </div>
        <li>
          <input type="number" placeholder="验证码" name="code" ng-model="code" required ng-minlength="6" ng-maxlength="6">
          <a class="getCode paraclass" ng-click="getCode()" ng-bind="paracont" ng-disabled="paraevent"></a>
        </li>
        <div ng-show="forget.code.$dirty && !forget.code.invalid">
          <p class="textinfo" ng-show="forget.code.$error.required">验证码必填</p>
          <p class="textinfo" ng-show="forget.code.$error.minlength">验证码为6位数字</p>
          <p class="textinfo" ng-show="forget.code.$error.maxlength">验证码为6位数字</p>
        </div>
      </ul>
      <p class="textinfo" ng-bind="mobiletest"></p>
      <a class="button button-warning next-btn">下一步</a>
    </div>
  </form>
    <div class="changePwd">
      <form novalidate name="changePwd">
      <ul>
        <li>
          <input type="password" placeholder="请输入新密码" required ng-model="newPwd" name="newPwd" ng-pattern="/^[a-zA-Z0-9]{6,20}/">
        </li>
        <div ng-show="changePwd.newPwd.$dirty && !changePwd.newPwd.invalid">
          <p class="textinfo" ng-show="changePwd.newPwd.$error.required">密码必须填</p>
          <p class="textinfo" ng-show="changePwd.newPwd.$error.pattern">密码由8-20位数字和字母组成</p>
        </div>
        <li>
          <input type="password" placeholder="再次输入新密码" name="resetPwd" ng-model="resetPwd" >
        </li>
        <div ng-show="changePwd.newPwd.$valid">
          <p class="textinfo" ng-show="newPwd != resetPwd">两次输入的密码不一致</p>
        </div>
      </ul>
      <a class="button button-warning next-btn">确认修改</a>
      </form>
    </div>
</div>
<script>
var myCtrl = angular.module('routingDemoApp', ['ngRoute','infinite-scroll'])
myCtrl.controller('forGetPassword',function($scope,$interval){
  $scope.paracont = "获取验证码";
  $scope.paraclass = "but_null";
  $scope.paraevent = true;
  var second = null,timePromise = undefined;
  $scope.getCode =function(){
    var mobile = $scope.mobile;
    if(second === null){
      second = 60;
      if(mobile == undefined || mobile ==""){
        $scope.mobiletest = "请输入手机号码";
        return false;
      }else{
        $scope.mobiletest = "";
        timePromise = $interval(function(){
          if(second<=0){
            $interval.cancel(timePromise);
            timePromise = undefined;
            second = null;
            $scope.paracont = "重发验证码";
            $scope.paraclass = "but_null";
            $scope.paraevent = true;
          }else{
            $scope.paracont = second + "s";
            second--;
          }
        },1000,100);
      }
    }else{
      return false;
    }
  }
});
</script>

以上所述是小编给大家介绍的AngularJS 实现点击按钮获取验证码功能实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

更多精彩内容其他人还在看

浅谈Koa2框架利用CORS完成跨域ajax请求

这篇文章主要介绍了浅谈Koa2框架利用CORS完成跨域ajax请求,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

浅析Vue中method与computed的区别

在new Vue的配置参数中的computed和methods都可以处理大量的逻辑代码,但是什么时候用哪个属性,要好好区分一下才能做到正确的运用vue。这篇文章主要介绍了Vue中method与computed的区别,需要的朋友可以参考下
收藏 0 赞 0 分享

Vue2.0 http请求以及loading展示实例

下面小编就为大家分享一篇Vue2.0 http请求以及loading展示实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

轻松搞定jQuery+JSONP跨域请求的解决方案

了解了jsonp之后,大家应该也都明白了,jsonp主要就是用来实现跨域的获取数据,今天我们就来详细探讨下如何在实际中应用jsonp实现跨域
收藏 0 赞 0 分享

Vue2.0实现组件数据的双向绑定问题

这篇文章主要介绍了Vue2.0实现组件数据的双向绑定问题,非常不错,具有参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

node的process以及child_process模块学习笔记

这篇文章主要介绍了node的process以及child_process模块学习笔记,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

vue2.0 循环遍历加载不同图片的方法

下面小编就为大家分享一篇vue2.0 循环遍历加载不同图片的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

浅谈Vue2.0中v-for迭代语法的变化(key、index)

下面小编就为大家分享一篇浅谈Vue2.0中v-for迭代语法的变化(key、index),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

使用vue-aplayer插件时出现的问题的解决

这篇文章主要介绍了使用vue-aplayer插件时出现的问题的解决,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Element-ui table中过滤条件变更表格内容的方法

下面小编就为大家分享一篇Element-ui table中过滤条件变更表格内容的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享
查看更多