在jQuery中使用setTimeout

问题描述 投票:0回答:2

我写了这段代码用jQuery来设计数字时钟,但我在某处跳过了主代码,所以无法得到结果。

 $( window ).load(function() {


    setTimeout(function(){

    var now=new Date();
    var clock= now.getHours() + ":" + now.getMinutes() + ":" + 
      now.getSeconds();
      $("#print").text(clock);
        },1000);
   });
javascript jquery load settimeout clock
2个回答
0
投票

使用 setInterval 而不是 setTimeout

$(window).on("load",function() {
        setInterval(function(){
         var now=new Date();
         var clock= now.getHours() + ":" + now.getMinutes() + ":" +  now.getSeconds();
         $("#print").text(clock);
        },1000);
    });
© www.soinside.com 2019 - 2024. All rights reserved.