【问题标题】:How do I link JS and CSS in a different directory to my HTML file?如何将不同目录中的 JS 和 CSS 链接到我的 HTML 文件?
【发布时间】:2021-08-18 02:23:01
【问题描述】:

我的文件位于完全不同的文件夹中。我试图从不同的路径调用 CSS 和 JS 文件。示例如下:

mainDirectory\internal\scripts\main.js
mainDirectory\internal\styles\main.css
mainDirectory\internal\pages\homePage.html -- (main page file)

我想在没有库的情况下这样做。

【问题讨论】:

    标签: javascript html css


    【解决方案1】:
    <!DOCTYPE html>
    <html lang="en" dir="ltr">
      <head>
        <meta charset="utf-8">
        <title>Test</title>
        <link rel="stylesheet" href="../folderThree\test.css">
        <script src="../folderTwo/test.js" type="text/javascript"></script>
      </head>
      <body>
        <p>Test</p>
      </body>
    </html>
    

    我能够确定我在这里犯了语法错误,因为我习惯了不同的系统。事实证明,我只需要../ 并将我的斜线从后向前交换。

    【讨论】:

      猜你喜欢
      • 2021-01-04
      • 1970-01-01
      • 2020-07-24
      • 1970-01-01
      • 2018-01-12
      • 2017-11-20
      • 2020-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多