简体   繁体   English

将CSS和js与HTML文件链接时遇到问题

[英]Having trouble linking css and js with HTML file

I can't link my css and js files to my html file. 我无法将CSS和js文件链接到html文件。

The most common problem I've seen with other peoples codes was that their files were not in the same folder but mine are and yet it is still not working. 我在其他人的代码中看到的最常见问题是,他们的文件不在同一文件夹中,而我的文件在同一文件夹中,但仍然无法正常工作。

<!DOCTYPE HTML>    
    <head>
        <link href="style.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <script type="text/javascript" src="app.js"></script>
    </body>
</html>

If you are using the following: 如果您使用以下内容:

<!DOCTYPE HTML>    
<head>
    <link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
    <script type="text/javascript" src="app.js"></script>
</body>

I expect your folder structure to be as follows: 我希望您的文件夹结构如下:

www/
   index.html
   app.js
   style.css

Is that correct? 那是对的吗?

Your code seems OK but what is the exact issue you face? 您的代码似乎还可以,但是您要面对的确切问题是什么? Both CSS and JS not loading? CSS和JS均未加载?

FYI the files do not need to be in the same directory. 仅供参考,文件不必位于同一目录中。 Usually, they are separated into folders to keep things clean: 通常,它们被分成文件夹以保持环境清洁:

www/
   index.html
   js/app.js
   css/style.css

Do you see any errors in your browser console? 您在浏览器控制台中看到任何错误吗? That could help you find the mistake 那可以帮助您发现错误

尝试这样做,使链接尽可能简单,例如,对于js,请在您的HTML中使用script标签,看看它是否有效,然后您进行链接

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

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