老师这个是怎么回事

老师这个是怎么回事

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!doctype html>
<html>
<head>
 <title>练习BOM</title>
 <meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
 <style type="text/css">
  .one{
   width:400px;
   height:100px;
   margin:120px auto;
   background-color:#dcdcdc;
   text-align:center;
   line-height:100px;
   border:1px red solid;
   position:relative;
  }
  .one span:nth-child(1){
   width:auto;
   height:auto;
   position:absolute;
   left:28px;
   top:38px;
   font-size:18px;
   font-weight:bold;
   color:#000;
  }
  .one .two{
   display:inline-block;
   width:19px;
   height:auto;
   font-size:18px;
   font-weight:bold;
   color:#666;
  }
  .one span{
   font:bold 21px "宋体",sans-serif;
   color:#666;
  }
 </style>
 <script type="text/javascript">
  window.onload=b;
  var s=new Date();
  var x=0,f=2,m=59;
  function b(){
   var M=59;
    var q=document.getElementsByClassName('two');
    var a=new Date(2017,0,0,x,f,m);
     q[0].innerHTML=a.getHours();
     q[1].innerHTML=a.getMinutes();
     q[2].innerHTML=a.getSeconds();
     m-=1;
     var c=setTimeout(b,10);
     console.log(a);
     if(a.getMinutes()==0 && a.getSeconds()==0){
      clearTimeout(c);
      alert('抢购已结束!!!');
      a.setHours(x);
      a.setMinutes(f);
      a.setSeconds(M);
      q[0].innerHTML=a.getHours();
      q[1].innerHTML=a.getMinutes();
      q[2].innerHTML=a.getSeconds();
     }
  }
 </script>
</head>
<body>
 <div class="one">
  <span>距抢购结束:</span>
  <div class="two">23</div>
  <span>:</span>
  <div class="two">59</div>
  <span>:</span>
  <div class="two">59</div>
 </div>
</body>
</html>


正在回答

登陆购买课程后可参与讨论,去登陆

3回答

经测试这两段代码是没有问题的哦,如下:

http://img1.sycdn.imooc.com//climg/5b6f7d750001b1be09040532.jpg

并没有出现你说的那种情况,刷新多次也是正常的。自己可以使用Chrome浏览器测试一下哦,祝学习愉快~~

  • 慕神6715844 提问者 #1
    就是当这一轮结束后,在if判断正确后开始一个抢购会从23点59分59秒开始倒计时。不是2分59秒了。。这是怎么回事那?如何修改?
    2018-08-12 10:39:02
  • 好帮手慕星星 回复 提问者 慕神6715844 #2
    经过多次测试,并没有出现23点59分59秒开始倒计时的情况,可以把你测试效果的效果截图一下哦。
    2018-08-13 09:49:06
提问者 慕神6715844 2018-08-11 00:42:20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!doctype html>
<html>
<head>
 <title>练习BOM</title>
 <meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
 <style type="text/css">
  .one{
   width:400px;
   height:100px;
   margin:120px auto;
   background-color:#dcdcdc;
   text-align:center;
   line-height:100px;
   border:1px red solid;
   position:relative;
  }
  .one span:nth-child(1){
   width:auto;
   height:auto;
   position:absolute;
   left:28px;
   top:38px;
   font-size:18px;
   font-weight:bold;
   color:#000;
  }
  .one .two{
   display:inline-block;
   width:19px;
   height:auto;
   font-size:18px;
   font-weight:bold;
   color:#666;
  }
  .one span{
   font:bold 21px "宋体",sans-serif;
   color:#666;
  }
 </style>
 <script type="text/javascript">
  window.onload=b;
  var x=0,f=2,m=59;
  function b(){
   var M=59;
    var q=document.getElementsByClassName('two');
    var a=new Date(0,0,0,x,f,m);
     q[0].innerHTML=a.getHours();
     q[1].innerHTML=a.getMinutes();
     q[2].innerHTML=a.getSeconds();
     m-=1;
     var c=setTimeout(b,10);
     if(a.getMinutes()==0 && a.getSeconds()==0){
      clearTimeout(c);
      alert('抢购已结束!!!');
      a.setHours(x);
      a.setMinutes(f);
      a.setSeconds(M);
      q[0].innerHTML=x;
      q[1].innerHTML=f;
      q[2].innerHTML=M;
     }
  }
  setInterval(function(){
   var s=new Date();
   if(s.getMinutes()==41 && s.getSeconds()==0){
   alert('开始下一轮抢购');
   b();
  }
  },800);
 </script>
</head>
<body>
 <div class="one">
  <span>距抢购结束:</span>
  <div class="two">23</div>
  <span>:</span>
  <div class="two">59</div>
  <span>:</span>
  <div class="two">59</div>
 </div>
</body>
</html>

还有老师为什么 开始下一轮的时候就会变成23点59分59秒了

提问者 慕神6715844 2018-08-11 00:33:57

为什么在等于0的时候已经结束定时器了,为什么还打印?

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码