首页 > 解决方案 >

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 托管网页

标签: javascriptjqueryhtml

解决方案


试试这个怎么样?

var counter =0 ; 

$(document).ready( function() {
  $('#auto').val("starting");
  refresh();
});


function refresh() {
   setInterval( function() {
   counter ++;
    $('#auto').val(counter);
  }, 1000);
}

推荐阅读