jQuery自动刷新页面上的时钟时间 [英] jQuery auto refresh page on clock time

查看:377
本文介绍了jQuery自动刷新页面上的时钟时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据时钟时间每15分钟自动刷新一次页面?

How do I refresh the page automatically every 15 minutes based on clock time?

例如:在9:00、9:15、9:30、9:45、10:00、10:15等刷新.

For example: refresh on 9:00, 9:15, 9:30, 9:45, 10:00, 10:15, so on..

我见过类似的想要的内容: https://stackoverflow.com/a/1217945/551559 但我认为这没有用.

I have seen one similar like I wanted : https://stackoverflow.com/a/1217945/551559 but I don't think it does the job.

setInterval(function(){
  // check clock time on every minute??
  if ( clock_time === '9:15' ) {

  }
},1000);

有人可以给我解决方案或任何链接吗?

Can someone give me a solution or any link to look at?

推荐答案

setInterval(function(){
    var minutes = (new Date()).getMinutes()
    if ( !minutes%15 ) location.reload(); // if minutes is a multiple of 15

},60000); // 60.000 milliseconds = 1 minute

解释if(!minutes%15):

minutes % 15是模运算.它将把分钟除以15,然后返回其余部分.因此,如果结果为0,则表示分钟是15的倍数.

minutes % 15 is a modulo operation. It will divide minutes by 15 and return the rest. So if the result is 0, it means that minutes is a multiple of 15.

现在我们需要反转该值:0等于false,所以我们想要!0(不是零= true)

Now we need to invert that value : 0 is equivalent to false, so we want !0 (not zero = true)

最后,如果分钟是15的倍数,我们得到的if( ! minutes % 15 )将为真.

Finally we get if( ! minutes % 15 ) will be true if minutes is a multiple of 15.

这篇关于jQuery自动刷新页面上的时钟时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆