点击按钮后,60秒倒计时后才能继续可以点击,按钮上还能显示倒计时

buyifly 2014-08-21 08:51:55


https://res.wx.qq.com/c/=/mpres/zh_CN/htmledition/js/register/step31ec5f7.js,/mpres/zh_CN/htmledition/js/register/step21ec5f7.js,/mpres/zh_CN/htmledition/js/register/step11ec5f7.js,/mpres/zh_CN/htmledition/js/wxverify/validateExtend1f192e.js,/mpres/zh_CN/htmledition/js/biz_common/jquery.validate1ec5f7.js,/mpres/zh_CN/htmledition/js/common/wx/Step1ec5f7.js,/mpres/zh_CN/htmledition/js/register/index1ec5f7.js

这是微信公众平台上的代码
function E() {
var e = $("#mobile"), t = (new Date).getTime(), n = Math.floor((t - b) / 1e3);
g && clearTimeout(g), n >= 60 ? (e.prop("readonly", !1), y = !0, $("#sendmobile").html("发送验证码").attr("disabled", !1).removeClass("btn_disabled")) : (e.prop("readonly", !0), y = !1, $("#sendmobile").attr("disabled", !0).addClass("btn_disabled").html("%s秒后可重发".sprintf(60 - n)), g = setTimeout(E, 1e3));
}
function S() {
function e() {
if (!y) return;
var e = $.trim(n.val());
l.mobile(e) ? t.attr("disabled", !1).removeClass("btn_disabled") : t.attr("disabled", !0).addClass("btn_disabled");
}
var t = $("#sendmobile"), n = $("#mobile");
n.keyup(e).blur(e), e(), t.click(function() {
var e;
t.attr("disabled") !== "disabled" && (e = "+86" + $.trim(n.val()), b = (new Date).getTime(), E(), o.post({
url: w ? "/cgi-bin/formbyskey" : "/acct/formbyticket",
data: {
form: "mobile",
action: "set",
f: "json",
mobile: e
},
mask: !1
}, function(e) {
var t = e.BaseResp.Ret;
if (t == 0) u.suc("验证码已经发送"); else {
switch (t) {
case -13:
u.err("登录超时,请重新登录");
break;
case -35:
u.err("该手机已经登记过2次,请使用别的手机号进行用户信息登记");
break;
default:
u.err("验证码发送失败");
}
b = 0;
}
}));
});
}


就是不知道怎么才能调用到自己的代码上来,求助,谢谢
...全文
1538 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
步慢生错 2014-08-22
  • 打赏
  • 举报
回复
引用 2 楼 buyifly 的回复:
谢谢楼上:) 越简单越好,也不要后台去校验,也不要去检查COOKIE了:) 谢谢!
删掉点不就是了
<script src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script>
<script>
    time1=60;
    time2=60;

    function countDown($obj){
        var time;
        //有几个按钮写几个类似的。
        if($obj.attr("id")=="b1")
        {
            time=--time1;
            if(time<=0){
                time1=60;
                $obj[0].disabled=!$obj[0].disabled
                clearInterval(inter1)
                $obj.text("点击发送")
                return
            }
        }
        if($obj.attr("id")=="b2")
        {    time=--time2;
            if(time<=0){
                time1=60;
                $obj[0].disabled=!$obj[0].disabled
                clearInterval(inter2)
                $obj.text("点击发送")
                return
            }
        }
        $obj.text(time+"秒后重新发送")
    }

    $(function(){
        $(".cd").bind("click",function(){
            $this=$(this);
            //没有被禁用时禁用并执行倒计时
            if(!$this[0].disabled){
                $this[0].disabled='disabled';
                if($this.attr("id")=="b1"){
                    inter1=setInterval(function(){countDown($this)},1000)
                }
                if($this.attr("id")=="b2"){
                    inter2=setInterval(function(){countDown($this)},1000)
                }

            }
        })
    })
</script>
<button id="b1" class="cd" >点击发送</button><br>
<button id="b2" class="cd" >点击发送</button><br>
buyifly 2014-08-22
  • 打赏
  • 举报
回复
谢谢楼上:) 越简单越好,也不要后台去校验,也不要去检查COOKIE了:) 谢谢!
步慢生错 2014-08-21
  • 打赏
  • 举报
回复
如果严格的话,这个还要结合后台获取时间的,要不然别人刷新一下就行了。 如果不严格,用个cookie也可以。 看起来容易,写起来挺麻烦的
<script src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script>
<script src="http://yukon12345.com/yukon12345.com/js/jquery.cookie.js"></script>
<script>
    time1=$.cookie("time1")||60;
    time2=$.cookie("time2")||60;
    dis1=$.cookie("dis1")
    dis2=$.cookie("dis2")
    function countDown($obj){

        var time;
        if($obj.attr("id")=="b1")
        {
            time=--time1;
            $.cookie("time1",time,{"expires":1});
            if(time<=0){
                time1=60;
                $obj[0].disabled=!$obj[0].disabled
                clearInterval(inter1)
                $obj.text("点击发送")
                $.cookie("dis1","")
                return
            }
        }
        if($obj.attr("id")=="b2")
        {    time=--time2;
            $.cookie("time2",time,{"expires":1});
            if(time<=0){
                time1=60;
                $obj[0].disabled=!$obj[0].disabled
                clearInterval(inter2)
                $obj.text("点击发送")
                $.cookie("dis2","")
                return
            }
        }

        $obj.text(time+"秒后重新发送")

    }

    $(function(){
        if(dis1="dis"){
            $("#b1")[0].disabled='disabled'
            inter1=setInterval(function(){countDown($("#b1"))},1000)
        }
        if(dis2="dis"){
            $("#b2")[0].disabled='disabled'
            inter2=setInterval(function(){countDown($("#b2"))},1000)
        }
$(".cd").bind("click",function(){
    $this=$(this);
    //没有被禁用时禁用并执行倒计时
    if(!$this[0].disabled){
    $this[0].disabled='disabled';
        if($this.attr("id")=="b1"){
            $.cookie("dis1","dis",{"expires":1})
          inter1=setInterval(function(){countDown($this)},1000)
        }
        if($this.attr("id")=="b2"){
            $.cookie("dis2","dis",{"expires":1})
          inter2=setInterval(function(){countDown($this)},1000)
        }

    }
})



})
</script>

<button id="b1" class="cd" >点击发送</button><br>
<button id="b2" class="cd" >点击发送</button><br>

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧