【问题标题】:Using setTimeout in jQuery在 jQuery 中使用 setTimeout
【发布时间】:2020-08-10 23:06:29
【问题描述】:

我已经编写了这段代码来用 jQuery 设计数字时钟,但是我在某个地方跳过了主要代码,所以无法得到结果。

 $( window ).load(function() {


    setTimeout(function(){

    var now=new Date();
    var clock= now.getHours() + ":" + now.getMinutes() + ":" + 
      now.getSeconds();
      $("#print").text(clock);
        },1000);
   });

【问题讨论】:

  • 使用setInterval 代替setTimeout

标签: javascript jquery load settimeout clock


【解决方案1】:

使用setInterval 而不是setTimeout

$(window).on("load",function() {
        setInterval(function(){
         var now=new Date();
         var clock= now.getHours() + ":" + now.getMinutes() + ":" +  now.getSeconds();
         $("#print").text(clock);
        },1000);
    });

【讨论】:

    猜你喜欢
    • 2013-10-15
    • 1970-01-01
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多