javascript - 如何在预设时间刷新代码的元素或特定部分?
问题描述
我目前有这段代码可以刷新整个 html 页面。在我的脚本中,我设法设置它,以便页面使用此函数在我的数据数组(由一系列时间值组成)中的每个时间值之前 10 分钟刷新。但是,这会重置我页面上的每个元素。有什么方法可以在预设时间(例如每天下午 12:50)刷新脚本中的特定元素,例如 div - 而不会干扰其他元素?
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);
}
解决方案
推荐阅读
- kubernetes - 通过 Kubernetes 使用 Terraform 动态配置 Cinder 卷和 Persistent 卷
- c# - 如何在上传和缩放时减小图像的大小(以 KB 为单位)?
- java - 运行一个简单的循环花费了太多时间
- exoplayer - Exoplayer FFmpeg audio Decoder?
- ios - Close iOS Keyboard by touching outside ( a smarter way)
- python - 如何在 django 中制作帖子标题列表
- sql-server - 循环使用动态表名和 where 子句存储过程
- php - 使用 Cron 和 swiftmailer 发送邮件
- android - 搜索显示错误项目的 ListView
- google-cloud-platform - GCP - 物联网核心监控消息