分享一个垃圾计时器(倒计时)

11 篇文章 0 订阅
8 篇文章 0 订阅
<html> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <script scr="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <!-- <script type="text/javascript" src="/static/js/jquery-1.11.3.min.js"></script> -->
<head>
    <style>
      .red {
        color: red;
      }
      .green {
        color: green;
      }
      .yellow {
        color: yellow;
      }
      #info {
        font-size: 40px;
      }
    </style>
    <script type="text/javascript"> 
        var t;
        function timedCount() { 
            var time = $("#info").text().split(":");
            var h = Number(time[0]);
            var m = Number(time[1]);

            if (h < 30) {
                $("#info").css("color","red");
                if (m%2 == 0) {
                  $("#info").hide();
                } else {
                  $("#info").show();
                }
            }
            if (h >= 30 && h <= 60) {
              $("#info").css("color",'yellow');
            } 
            if (h > 60) {
              $("#info").css("color","green");
            }
            if (m == '00') {
              h = h - 1;
              m = 60;
              m = m -1;
            } else {
              m = m - 1;
              if (m == 0) m = "00";
            }
            $('#info').text(h + ":" + m);
            if (h == 0 && m =="00") {
              alert('时间用完啦!!!');
            } else {
               t = setTimeout("timedCount()",1000);
            }
        } 
        function stopCount() { 
          clearTimeout(t); 
        }
        var time_info = function() {
            var hour = document.getElementById('txt1').value;
            var miniute = document.getElementById('txt2').value;
            var info = hour*60 + Number(miniute) + ":00";
            $('#info').text(info);
        }
    </script>
</head> 
<body> 
<form> 
<input type="text" id="txt1" placeholder="请输入小时"> 
<input type="text" id="txt2" placeholder="请输入分钟">
<input type="button" value="生成时间" onClick="time_info()">
<div style="width: 500px;height: 80px;line-height: 80px;">
    <span id ="info" class="time_info"></span>
</div>

<input type="button" value="开始计时" onClick="timedCount()"> 
<input type="button" value="停止计时!" onClick="stopCount()"> 
</form> 
<p>输入小时和分钟之后开始计数。</p>  
</body> 
</html> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值