zoukankan      html  css  js  c++  java
  • 倒计时验证码

    //获取手机验证码
    $scope.regInfo = {
    phone: "15139000000",
    code: "",
    text: "发送验证码",
    };
    $scope.second = 0;
    $scope.currentCode = "";
    $scope.creatCode = function () {
    var Num = "";
    for (var i = 1; i < 7; i++) {
    Num += Math.floor(Math.random() * 10);
    }
    return Num;
    };

    $scope.getcode = function () {
    //alert("123456");
    //测试阶段,不用每次发短信,先默认通过验证
    //return;
    $rootScope.showAlert("此功能暂未开通!");
    return;
    if ($scope.second != 0) {
    return;
    }
    var reg = /^0?1[3|4|5|8][0-9]d{8}$/;
    if (!reg.test($scope.loginfo.userinfo)) {
    $rootScope.showAlert("请输入有效的手机号!");
    return;
    }
    //生成验证码
    $scope.currentCode = $scope.creatCode();

    //发送验证码
    var args = {
    mobile: $scope.loginfo.userinfo,
    content: "【EzTrader】您的验证码是" + $scope.currentCode + ",有效时间5分钟,请不要告诉他人",
    tag: 2,
    headers: {
    "apikey": "300233c8f5c8a11b0117a64ed08e9d80",
    }
    };

    var timePromise = undefined;

    var dx = $resource('http://apis.baidu.com/kingtto_media/106sms/106sms', args, {
    get: {
    method: 'GET',
    isArray: false,
    headers: { 'apikey': "300233c8f5c8a11b0117a64ed08e9d80" }
    }
    });
    dx.get(args, function (data) {
    if (timePromise) {
    return;
    }
    $scope.second = 60;
    timePromise = $interval(function () {
    if ($scope.second <= 0) {
    $interval.cancel(timePromise);
    timePromise = undefined;
    $scope.regInfo.text = "重发验证码";
    } else {
    $scope.regInfo.text = $scope.second + "秒后可重发";
    $scope.second--;

    }
    }, 1000, 100);
    console.log(data);
    });
    };
  • 相关阅读:
    getBoundingClientRect()方法
    Sublime Text3 安装less
    less知识点总结(一)
    跨域知识(二)——JSONP
    面向过程和面向对象的区别(转)
    暴力+DP:买卖股票的最佳时机
    车的可用捕获量(3.26leetcode每日打卡)
    三维形体的表面积(3.25leetcode每日打卡)
    基础练习:FJ的字符串
    DP:打家劫舍
  • 原文地址:https://www.cnblogs.com/xfcao/p/8668335.html
Copyright © 2011-2022 走看看