【发布时间】:2021-11-21 16:50:29
【问题描述】:
我有一个 html 文件,其中显示了两个 Tabulator 表。表 1 连接到 saveFile1.json,表 2 连接到 saveFile2.json。我的问题是,saveFile2.json 中的 <script> 覆盖了 saveFile1.json 中的 <script>,因此两个表都显示了 saveFile2.json 中的内容。我怎样才能解决这个问题?谢谢。
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="MyCSS.css" >
<script type="text/javascript" src="node_modules/tabulator-tables/dist/js/tabulator.js"></script>
</head>
<body>
<table>
<td>
<div id="table1"></div>
<script type="text/javascript" src="saveFile1.json"></script>
</td>
<td>
<div id="table2"></div>
<script type="text/javascript" src="saveFile2.json"></script>
</td>
</table>
<script type="text/javascript" src="tabulatorTables.js"></script>
</body>
</html>
【问题讨论】:
-
您在询问 Javascript 但您没有显示代码?
-
使用不同的变量名和/或模块。
-
@CharlesEF 上次我遇到了一个类似的问题,我只需要在 html 文件中切换
<script>标记的位置即可使其工作。所以我的想法是,这次解决方案可能是类似的。 -
@jabaa 你知道一个可以解决我的“双json问题”的模块吗?
-
您应该将脚本加载为模块:developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules。您应该使用正确的命名约定。
saveFile1.json不能是 JSON 文件。这是一个 JavaScript 文件。你应该把它命名为saveFile1.js。
标签: javascript html tabulator