我有一些从另一个文件导入的 js 代码,其中有一个变量,我想在我的 HTML 文件中更新。如何在不将 js 代码粘贴到我的 HTML 文件中的情况下更新变量?
JS(脚本.js):
var link = "https://example.com"
var codeBlock = `...some html code... ${link} ...some more html code`;
document.getElementById("div").innerHTML = codeBlock
HTML:
<div id="div"></div>
<script src= "script.js"></script>
<script>
//I want to change this variable
var link = "https://anotherexample.com"
</script>