• JQuery 解决按钮上的倒计时问题


    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Insert title here</title>
            <script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
            <style type="text/css">
                .btn {
                     100px;
                    height: 50px;
                    background-color: lightgoldenrodyellow;
                }
            </style>
        </head>
    
        <body>
            <input type="button" id="btnid" name="butname" value="同意" class="btn" disabled="disabled" /><br /><br />
            <input type="button" id="btnCid" name="butname" value="变化" class="btn" disabled="disabled" />
            <!--    在页面中有一个同意按钮,要求按钮默认不可点击,
    在5秒之后才可以点击这个按钮
    按钮可用状态时,点击按钮,按钮变为不可用状态,在5秒之后才可以点击这个按钮
    
    -->
            <script type="text/javascript">
                $(function() {
                    showNumber();
                })
                function showNumber(){
                    for(var i = 1; i <=5; i++) {
                        setTimeout("show("+i+")", i * 1000);//注意setTimeout方法中带参数的方法特殊处理,双引号不能包含变量
                    }
                }
                function show(i){
                    var x=6-i;
                    $("#btnCid").val("变化 "+x);
    //                alert(x);
                    if(x==1){
                        setTimeout("showbtn()",1000);  //注意 效果有1秒的延迟,所以这里要等上1秒
                    }
                }
                function showbtn(){
                alert("可用");
                $("#btnCid").removeProp("disabled");
                }
                $("#btnCid").click(function(){
                disablebtn();
                showNumber();
                })
                function disablebtn(){
                $("#btnCid").prop("disabled","disabled");
            }
            </script>
    <!-- 下边这个不带倒计时数字 -->
            <!--<script type="application/javascript">
            $(function(){
                setTimeout("showbtn()",5000);
            });
            
            function showbtn(){
                alert();
                $("#btnid").removeProp("disabled");
            }
            $("#btnid").click(function(){
                disablebtn();
                setTimeout("showbtn()",5000);
            })
            function disablebtn(){
                $("#btnid").prop("disabled","disabled");
            }
        </script>-->
    
        </body>
    
    </html>
  • 相关阅读:
    高并发第八弹:J.U.C起航(java.util.concurrent)
    高并发第七弹:不可变对象及常用的工具类
    高并发第六弹:线程封闭(ThreadLocal)
    分布式爬取链家网二手房信息
    scrapy CrawlSpider爬取猎云网文章数据
    selenium实现12306网站自动抢票
    王者荣耀官方壁纸爬取
    使用 vsftpd 服务传输文件
    使用 Apache 服务部署静态网站
    iptables 与 firewalld 防火墙
  • 原文地址:https://www.cnblogs.com/qingyundian/p/8722018.html
Copyright © 2020-2023  润新知