Javascript “./”(点斜线)在 HTML 文件路径位置方面指的是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7591240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does "./" (dot slash) refer to in terms of an HTML file path location?
提问by Simon Suh
I know ../
means go up a path, but what does ./
mean exactly?
我知道../
意味着走一条路,但究竟./
是什么意思?
I was recently going through a tutorial and it seems to be referring to just a file in the same location, so is it necessary at all? Can I just not use it if that's all it's doing?
我最近正在阅读一个教程,它似乎只是指同一位置的一个文件,所以有必要吗?如果仅此而已,我可以不使用它吗?
采纳答案by Coomie
./
is the the folder that the workingfile is in:
./
是工作文件所在的文件夹:
So in /index.htm
./
is the root directory
but in /css/style.css
./
is the css folder.
所以 in/index.htm
./
是根目录,
但 in/css/style.css
./
是 css 文件夹。
This is important to remember because if you move CSS from /index.htm
to /css/style.css
the path will change.
记住这一点很重要,因为如果将 CSS 从 移动/index.htm
到/css/style.css
路径将会改变。
回答by Sourabh
/
means the root of the current drive;
/
表示当前驱动器的根;
./
means the current directory;
./
表示当前目录;
../
means the parent of the current directory.
../
表示当前目录的父目录。
回答by GibboK
You can use the following list as quick reference:
您可以使用以下列表作为快速参考:
/ = Root directory
. = This location
.. = Up a directory
./ = Current directory
../ = Parent of current directory
../../ = Two directories backwards
Useful article: https://css-tricks.com/quick-reminder-about-file-paths/
有用的文章:https: //css-tricks.com/quick-reminder-about-file-paths/
回答by Brad Christie
. = This location
.. = Up a directory
So, ./foo.html
is just foo.html
. And it is optional, but may have relevance if a script generated the path (relevance to the scriptthat is, not how the reference works).
所以,./foo.html
只是foo.html
。它是可选的,但如果脚本生成了路径,则可能具有相关性(与脚本的相关性,而不是引用的工作方式)。
回答by Brad
Yes, ./
means the current working directory. You can just reference the file directly by name, without it.
是的,./
表示当前工作目录。您可以直接按名称引用该文件,而无需它。
回答by Yevgeny Simkin
You are correct that you can omit it. It's useful only for clarity. There is no functional difference between it being there and not being there.
你是对的,你可以省略它。它只是为了清楚起见有用。它在那里和不在那里之间没有功能上的区别。
回答by Roko C. Buljan
A fast and small recap about paths
关于路径的快速小回顾
Absolute paths
绝对路径
http://website.com/assets/image.jpg
IF the image is not on your domain- go look there for image
http://website.com/assets/image.jpg
如果图像不在您的域中- 去那里寻找图像
//website.com/assets/image.jpg
image loaded using http or https protocols
//website.com/assets/image.jpg
使用 http 或 https 协议加载的图像
Relative paths
相对路径
(For internal useif the image is on the same server)
(供内部使用,如果图像在同一台服务器上)
image.jpg
imagein the same place as the document calling the image!
image.jpg
图像与调用图像的文档位于同一位置!
./image.jpg
Same as above, imagein the same place as the document calling the image!
./image.jpg
同上, image和调用image的文档在同一个地方!
/assets/image.jpg
Similar to Absolute Paths, just omitting the protocol and domain name
Go search my image starting from my root folder /
, than into assets/
/assets/image.jpg
类似于绝对路径,只是省略了协议和域名
从我的根文件夹开始搜索我的图像/
,而不是进入assets/
assets/image.jpg
this time assetsis in the same place as the document, so go into assetsfor the image
assets/image.jpg
这次资产与文档在同一位置,因此进入图像的资产
../assets/image.jpg
From where the document is, go onefolder back../
and go into assets
../assets/image.jpg
从文档所在的位置,返回一个文件夹并进入../
assets
../../image.jpg
go twofolders back, there's my image!
../../image.jpg
去2个夹背,还有我的形象!
../../assets/image.jpg
go twofolders back../../
and than go intoassets
../../assets/image.jpg
去2个夹背../../
,比进入assets
回答by Roko C. Buljan
Yeah ./
means the directory you're currently in.
是的./
表示您当前所在的目录。
回答by Jenifer Venitta
For example css files are in folder named CSS
and html files are in folder HTML
, and both these are in folder named XYZ
means we refer css files in html as
例如css文件在文件夹中CSS
,html文件在文件夹中HTML
,这两个文件夹都在文件夹中XYZ
意味着我们将html中的css文件称为
<link rel="stylesheet" type="text/css" href="./../CSS/style.css" />
Here ..
moves up to HTML
and .
refers to the current directory XYZ
这里上..
移HTML
并.
指向当前目录XYZ
---by this logic you would just reference as:
---通过这种逻辑,您可以将其引用为:
<link rel="stylesheet" type="text/css" href="CSS/style.css" />
回答by Musaranio
In reference to the quick reference list, specifically you can use the following :
关于快速参考列表,具体可以使用以下内容:
\.\ Root Directory + Current directory (Drive Letter)
\.\ 根目录 + 当前目录(盘符)