首页 > 移动平台 > 详细

javascript手机短信倒计时120s

时间:2014-03-28 14:39:42      阅读:579      评论:0      收藏:0      [点我收藏+]

function countDown(){
    var time = $(".e-time strong").text();
    $(".e-time strong").text(time - 1);
    if (time == 1) {
        $(".timeDiv").hide();
        $(".sendMobileCode").show();
        $(".e-time strong").text(119);
    } else {
        setTimeout(countDown, 1000);
    }
}

或者

var counttimer =120;
    var timerset =null;
    $(‘.reg_phone .a1‘).bind("click",countime);
    function countime(){
            var mobile = $(‘#user_phone‘).val();
            var mobileReg = /^1[358][0-9]{9}$/;
            if(mobileReg.exec(mobile)){
                 var params = ‘mobile=‘+mobile;
                $.ajax({
                    url:‘/user.php?act=send_pwd_code&is_ajax=true‘,
                    data:params,
                    dataType:‘json‘,
                    type:‘post‘,
                    success:function(res){
                        if(res.error == 1){
                            PopFn(res.msg);
                        }else{
                            $(‘.reg_phone .a1‘).html("<span class=‘cut_timer‘>120</span>" + "秒后重新获取").css({"cursor" : "text"});
                            
                            if($(".cut_timer").length > 0){
                                timerset = setInterval(function(){
                                    counttimer--;
                                    $(".cut_timer").html(counttimer);
                                    if(counttimer == 0){
                                        clearInterval(timerset);
                                        $(‘.reg_phone .a1‘).html("获取短信验证码").css({"cursor" : "pointer"}).bind("click",function(){
                                                countime();
                                        });
                                        counttimer =120;
                                    }
                                },1000);                
                            };
                            
                            $(‘.reg_phone .a1‘).unbind("click");
                        }
                    }
                });
            }else{
                PopFn(‘请输入手机号码‘);
            }
    };

 

function timeshow(obj,second, link){
    setTimeout(fun, 1000);
    var funTime =second;
    function fun(){
        funTime--;  
        $(obj).html(funTime)
        if (funTime == 1){
                        if(link){
                            window.location.href = link;
                        }else{
                            window.location.href = "/";       
                        }
        }else{
            setTimeout(fun, 1000);
        }
    }
}

javascript手机短信倒计时120s,布布扣,bubuko.com

javascript手机短信倒计时120s

原文:http://www.cnblogs.com/lglijing/p/3630310.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!