【发布时间】:2013-12-03 22:54:30
【问题描述】:
好的,所以我正在创建一个广播播放器,基本上我需要 Title、Content div、Next show Div 在某些时间刷新,例如上午 9 点和下午 12 点。我有 JQuery 代码可以在某个时间刷新页面,但这并不是我所追求的。有什么想法吗?
代码:
function refreshAt(hours, minutes, seconds) {
var now = new Date();
var then = new Date();
if(now.getHours() > hours ||
(now.getHours() == hours && now.getMinutes() > minutes) ||
now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
then.setDate(now.getDate() + 1);
}
then.setHours(hours);
then.setMinutes(minutes);
then.setSeconds(seconds);
var timeout = (then.getTime() - now.getTime());
setTimeout(function() { window.location.reload(true); }, timeout);
}
然后我只需通过在我的页面上插入以下内容来调用 refreshAt 函数
<script type="text/javascript">refreshAt(04,30,0);</script> //page refreshes at 4:30am.
所以这会刷新整个页面。我只需要刷新标题和 2 个 div。 我需要在代码中添加/更改什么。
【问题讨论】:
-
你刷新 div 背后的主要逻辑是什么你试图刷新以在 div 中加载一些数据?
-
你好@Veerendra,它背后的逻辑是说就像一个演示者正在播出例如“约翰史密斯 - 09:00”,当下一位主持人在 12:00 播出时,我希望 div更改为“Peter Smith - 12:00”,听众无需刷新。