javascript - 仅使用 setinterval 更新 div
问题描述
我正在尝试使用 setinterval 每隔一定时间更新一个表,如果表被更新,问题是整个页面都被更新并且加倍,这是一个示例代码:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
</head>
<body>
<h1>hello</h1>
<div id="updategreeting">
<h2>hello2</h2>
</div>
</body>
</html>
<script type="text/javascript">
$(document).ready(function() {
setInterval(
function() {
$("#updategreeting").empty().load("#updategreeting");
}, 10000
);
});
</script>
在导航器中执行时会显示(hello hello2),但是当以设置的间隔充电时会显示(hello hello hello2)
然后如果我只想更新 div(updategreeting)而不加载(hello),我希望你能帮助我,谢谢。
解决方案
推荐阅读
- javascript - Javascript 执行顺序:cookie 是否总是在重定向之前设置?
- css - css 动画旋转 - 如何让 2 个元素同时旋转?
- user-interface - 如何取消 xcoms 在气流 UI 中的显示
- node.js - restify 中如何支持可选参数?
- python - 使用唯一的值更改重复项
- google-apps-script - 在谷歌电子表格中获取用户的电子邮件
- powershell - 需要帮助用于 RAM 检查的 PowerShell 脚本
- python - 无法在配置文件模板上显示登录用户配置文件详细信息?
- eclipse - 无法强制 gcc 链接器删除未使用的功能
- google-apps-script - 如何更改代码以应用于命名工作表选项卡,而不是 Google 电子表格中的第一个工作表选项卡