简体   繁体   English

无法在html头中链接CSS和JS文件

[英]Trouble linking css and js files in html head

I have been studying Web Development for the past couple months and have consistently had trouble with linking to both local and global files in html. 在过去的几个月中,我一直在学习Web开发,并且一直无法链接到html中的本地文件和全局文件。 I'm wondering if there is something I'm missing, usually when I'm experimenting with bootstrap for example I will simply go on bootstraps site and copy the links from their getting started page. 我想知道是否缺少某些东西,通常例如在尝试使用Bootstrap时,我会直接进入Bootstraps网站并从其入门页面复制链接。 For whatever reason the css will link fine but the js file will not. 无论出于何种原因,css都可以很好地链接,但是js文件不能。 To test the functionality I just copy some of their code examples and paste them and the styling works fine but the js functionally doesn't. 为了测试功能,我只复制了他们的一些代码示例并粘贴了它们,然后样式就可以了,但是js在功能上却不行。 That's just one example of something I have been dealing with since I started Web Development. 这只是我开始Web开发以来一直在处理的事情的一个示例。 It's very discouraging to literally copy and paste links like that and have it not work. 从字面上复制并粘贴这样的链接并使其不起作用是非常令人沮丧的。 I feel like I could be making some simple mistake but I'm just not sure. 我觉得我可以进行一些简单的错误,但我只是不知道。 I'm always careful to include the files in the order that they need to be compiled (external js files that I use before my own files, etc.) And I also always test to see if I'm using the wrong '/' and I still can't consistently get external links to function properly. 我总是小心地按照需要编译的顺序包含这些文件(在我自己的文件之前使用的外部js文件等),并且我还经常测试以查看是否使用了错误的'/'而且我仍然无法始终如一地使外部链接正常运行。 Is there something I'm missing? 有什么我想念的吗?

This most likely has to do with the Same-Origin Policy 这很可能与“ 同源政策”有关

The easiest alternative here would be to use something like JSFiddle or simply download the js files. 这里最简单的替代方法是使用JSFiddle之类的东西或直接下载js文件。 If you want a truly interactive web development workflow, use Google Chrome's development tools with workspaces . 如果您需要真正的交互式Web开发工作流,请使用带有工作区的 Google Chrome开发工具。

It'll allow you to live edit js/css files on the fly and see the changes as you make them. 它使您可以实时地实时编辑js / css文件,并在进行更改时查看它们。 This is really good for someone still trying to learn the ropes as it'll give you constant feedback. 这对于仍在尝试学习绳索的人来说真的很不错,因为它会不断给您反馈。

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

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