动手写一个用户注册协议倒计时

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>注册</title>
    <script type="text/javascript">
        //用户有十秒钟的时间看协议,超过十秒钟,“同意”按钮将生效
        var Seconds = 10;
        //计时器ID
        var setIntervalID;
        function ok() {
            var getid = document.getElementById("but");
            if (Seconds <= 0) {
                getid.value="同意";
                getid.disabled = false; //或者写成getid.disabled=""; 启用getid控件。
                //停止计时器
                clearInterval(setIntervalID);

            }
            else {
                getid.value = "请仔细阅读协议还剩下【" + Seconds + "】秒";
            }
            Seconds--;
        }

      setIntervalID=setInterval("ok()", 1000);
        
    </script>
</head>
<body>
<textarea  cols="20" rows="8"></textarea><br />
<!--disabled="disabled" 默认submit表单是禁用的,也就是只读的,不能点击-->
<input type="submit" id ="but" value="同意" disabled="disabled" />

</body>
</html>


方法二

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="jquery-1.11.2.js"></script>
</head>
<body>
    <form action="http://www.helloweba.com/" method="post" name="agree">
        <input type="submit" class="button" value="" name="agreeb">
    </form>
</body>
</html>
<script>
    var secs = 5;
    var si;
    $(function () {
        $(".button").attr("disabled", "disabled");
        $(".button").val("请认真查看<服务条款和声明>(" + secs + ")")
        si = setInterval(a, 1000);
        
    })

    function a() {
       
        $(".button").val("请认真查看<服务条款和声明>(" + (secs-1) + ")");
        if (secs == 0) {
            clearInterval(si);
            $(".button").val("我同意" ).removeAttr("disabled");
        }
        secs--;
    }
</script> 

方法三(别人写的高质量代码)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form action="http://www.helloweba.com/" method="post" name="agree">
        <input type="submit" class="button" value="请认真查看<服务条款和声明> (30)" name="agreeb">
    </form> 
</body>
</html>
<script>
    var secs = 30;
    document.agree.agreeb.disabled = true;

    for (var i = 1; i <= secs; i++) {
        window.setTimeout("update(" + i + ")", i * 1000);
    }
    function update(num) {
        if (num == secs) {
            document.agree.agreeb.value = " 我 同 意 ";
            document.agree.agreeb.disabled = false;
        }
        else {
            var printnr = secs - num;
            document.agree.agreeb.value = "请认真查看<服务条款和声明> (" + printnr + ")";
        }
    }

</script> 


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值