您的位置:首页 > 其它

获取手机验证码并计时

2015-12-18 10:19 232 查看
<a href="javascript:;" onclick="SendPhoneCode()" id="getpCode">获取手机验证码</a>

<script type="text/javascript">

    function SendPhoneCode() {

        alert("12");

        jQuery("#getpCode").attr("onclick", "return false;").html("正在发送.....");

        //timtout方法可以写在AJXC里,等发送短信请求成功后再执行

        timtout(jQuery("#getpCode"), new Date().getTime(), 10, "");

    }

    //发送短信倒计时

    function timtout(objs, obj, time, fun) {

        var s = time - parseInt((new Date().getTime() - obj) / 1000);

        if (s <= 0) {

            objs.attr("onclick", fun).html("发送验证码");

            return;

        }

        objs.html(s + "秒后获取")

        setTimeout(function () { timtout(objs, obj, time, fun) }, 500);

    }

</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: