You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何脚本无法更新页面元素内容?环境问题排查求助

问题描述

我这段代码在其他环境中实现过相同功能且可正常运行,因此怀疑是环境问题。我预期该脚本能将ID为demo的元素内容更新为"hi",相关代码如下:

HTML代码

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>replit</title>
  <link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
  <div id="demo">before</div>
</body>

</html>

CSS代码

html, body {
  height: 100%;
  width: 100%;
}

JavaScript代码

const box = document.getElementById("demo");
box.innerText = "hi";

内容的提问来源于stack exchange,提问作者Margaret Guzman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 09:34:49