简体   繁体   English

如何为 HTML 个页面使用相同的 JS 文件?

[英]How to use same JS files for HTML pages?

At the moment, the files setup looks like this: File Setup in the merkur.html file I use this to go to the JS files:目前,文件设置如下所示: merkur.html 文件中的文件设置我将其用于 go 到 JS 文件:

<script src="../scripts/ui.js"></script>
<script src="../scripts/index.js"></script>

The JS is only working on the index.html, in the merkur.html I get the error: Error Message JS 仅在 index.html 上工作,在 merkur.html 中我收到错误消息:错误消息

Can somebody help me?有人可以帮我吗?

In your index.html file, keep the links to your JavaScript files as bellow.在您的 index.html 文件中,保留指向您的 JavaScript 文件的链接,如下所示。

<script src="scripts/ui.js"></script>
<script src="scripts/index.js"></script>

In your merkur.html file, keep the links to your JavaScript files as bellow.在您的 merkur.html 文件中,保留指向您的 JavaScript 文件的链接,如下所示。

<script src="../scripts/ui.js"></script>
<script src="../scripts/index.js"></script>

If you are still getting errors, you may have do something wrong in your JavaScript codes.如果您仍然遇到错误,则您的 JavaScript 代码可能有问题。 Maybe you are trying to search for an HTML element which doesn't exist in your relevant HTML code.也许您正在尝试搜索 HTML 元素,但您的相关 HTML 代码中不存在该元素。

Thanks and best regards!谢谢并致以最诚挚的问候!

You can use js files in any html document.您可以在任何 html 文档中使用 js 文件。 The only one problem here is a path you wrote for merkur.html file.这里唯一的问题是您为merkur.html文件编写的路径。

So just read how to deal with path to files.因此,只需阅读如何处理文件路径即可。 Especially ../ & ./特别是../ & ./

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM