时间每5秒重新加载一次setinterval jquery

时间:2018-03-16 15:22:34

标签: jquery

我希望div重新加载它的时间每5秒显示一次。

JQUERY 这是一种方法......

time_showed1=$.now();//how to format in segs, then mins, then hours..

setInterval(function() { time_showed=time_showed1;}, 5000);

("#container").append("updated at:"+time_showed+" time");

HTML

  <div id="container"></div>

我也试过这个但没有什么

myFunction = function() { 

        time_showed=$.now();
    };


      setInterval(myFunction(), 2000);

1 个答案:

答案 0 :(得分:0)

setInterval(function() { 
    time_showed = time_showed1;
    ("#container").append("updated at:" + time_showed + " time");
}, 5000);

您需要在setInterval调用的函数内设置时间。并且

myFunction = function() {     
    time_showed=$.now();
    ("#container").append("updated at:" + time_showed + " time");
};
setInterval(myFunction, 2000);

你需要将一个函数传递给setInterval,你传递了结果。

相关问题