javascript - html页面中的值未更新
问题描述
我正在使用 jquery 自动更新 HTML 页面的一部分。以下是代码
$(document).ready( function() {
$('#auto').load("static/l.txt");
refresh();
});
function refresh() {
setTimeout(function() {
$('#auto').load("static/l.txt");
refresh();
}, 1000);
}
要更新的 HTML div 标签的id是auto 文件 static/l.txt 正在被另一个 python 程序不断更新。
但是当我加载 html 页面时,div 只会更新一次,并且不会更新值,除非我在浏览器上打开开发人员控制台。
我在 python 中使用 Flask 托管网页
解决方案
试试这个怎么样?
var counter =0 ;
$(document).ready( function() {
$('#auto').val("starting");
refresh();
});
function refresh() {
setInterval( function() {
counter ++;
$('#auto').val(counter);
}, 1000);
}
推荐阅读
- android - 在 IONIC3 中启动屏幕后在 android 上运行卡住
- html - 如何将图像从网格容器扩展到视口边缘?
- r - dplyr::count 省略未表示的级别
- android - 无法从 Android Studio 中的 AdMop 加载广告
- python - 使用条件语句设置 python 变量
- javascript - fetch 调用给出错误
- javascript - Contenteditable 事件 - Jquery
- c# - 如何使用 Entity Framework Core 解决方案实现楼梯模式?
- php - 在没有 BOM 的情况下以 UTF-8 编码 php 文件
- node.js - 从 mongodb 数组获取最后 2 天/分钟