我正在使用 Visual Studio 代码,并且我已经安装 LiveServer 来运行 JavaScript 代码。但是 Javascript 代码没有在 Live Server 中运行,只有 HTML 代码正在运行并显示
1 回答

DIEA
TA贡献1820条经验 获得超2个赞
VSC 的 LiveServer 扩展的目的是将您的工作区目录localhost:5000以index.html(如果存在)作为入口点公开。如果您想通过 LiveServer 执行任何 JavaScript,您需要首先在 HTML 文件中使用headorbody元素中的脚本标记来实现它。
// this is my main.js located in scripts catalog
document.getElementById("script").innerHTML = 'Hello World'
<script src="scripts/main.js"></script>
<h1 id="script"></h1>
添加回答
举报
0/150
提交
取消