简体   繁体   English

将外部css / js文件包含到html页面中

[英]Include external css/js file into html page

I'm trying to link manually my CSS and Javascript files to my HTML scripts, but I've never really done it with files from a different folder /directory. 我正在尝试将我的CSS和Javascript文件手动链接到我的HTML脚本,但我从来没有真正使用来自不同文件夹 /目录的文件 This is what I have so far: 这是我到目前为止:

<link rel="stylesheet" type="text/css" href="/Desktop/Script/CSS/tempeststyle.css"/>
<link rel=script" type="text/javascript" href="/Desktop/Script/Javascript/tempestscript.js"/>

I've read from a few sources that you don't have to start all the way at C:/Users or whatever the case may be for different systems, but I'm not sure if these links are acceptable the way they are (ie, them starting at "/Desktop"). 我从一些消息来源中读到,您不必一直在C:/Users或不同情况下可能用于不同系统,但我不确定这些链接是否可以接受(即,他们从“/桌面”开始。 The files are in separate folders within the same folder on the desktop. 这些文件位于桌面上同一文件夹中的单独文件夹中。 So how to include them the best way ? 因此,如何将他们的最好方法是什么? Thanks. 谢谢。

If you want to add scripts from local path you can use a relative path: 如果要从本地路径添加脚本,可以使用相对路径:

<link rel="stylesheet" type="text/css" href="../CSS/tempeststyle.css"/>

or relative path from your web root folder: 或来自您的Web根文件夹的相对路径:

<link rel="stylesheet" type="text/css" href="/styles/CSS/tempeststyle.css"/>

or filesystem absolute path: 或文件系统绝对路径:

<link rel="stylesheet" type="text/css" href="file:///C:/Path/To/Scripts/styles/CSS/tempeststyle.css"/>

It is rather better if you use an absolute path from your web server: 如果您使用Web服务器的绝对路径,那就更好了:

<link rel="stylesheet" type="text/css" href="http://www.example.com/styles/CSS/tempeststyle.css"/>

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

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