qq_25135027 2021-06-04 02:32 采纳率: 66.7%
浏览 67
已采纳

怎麽讓HTML倒數計時器的Console.log不換行。

        <!DOCTYPE html>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <html>
        <head>
        <meta charset="utf-8">
        </head>
        <style>
        #demo{
          text-align:center;

     }
        </style>
        <body>
            <section class="center">
        <p class="demo"   id="demo"></p>
      

        <script>
        
        // Set the date we're counting down to
    var countDownDate = new Date("Jun 10, 2021 18:00:00").getTime();

        // Update the count down every 1 second
        var x = setInterval(function() {
          // Get today's date and time
          var now = new Date().getTime();
            
          // Find the distance between now and the count down date
          var distance = countDownDate - now;
        
          // Time calculations for days, hours, minutes and seconds
          var days = Math.floor(distance / (1000 * 60 * 60 * 24));
          var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
          var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
          var seconds = Math.floor((distance % (1000 * 60)) / 1000);
          // Output the result in an element with id="demo"
        };
            document.getElementById("demo").innerHTML = days + "天 " + hours + "小時 " + minutes + "分鐘 " + seconds + "秒 ";
          console.log(distance);
        // If the count down is over, write some text 
       
        
          if (distance < 0) {
     clearInterval(x);

  }
}, 1000);
        </script>
        </body>
        </html>

 

  • 写回答

5条回答 默认 最新

  • CSDN专家-文盲老顾 2021-06-04 14:46
    关注

    在每次console.log之前,加一句console.clear()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵