Html 'url'、'src' 和 'href' 之间的差异
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12032337/
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
Differences between 'url', 'src', and 'href'
提问by OneChillDude
Possible Duplicate:
Difference between SRC and HREF
可能的重复:
SRC 和 HREF 之间的差异
When writing html/css, it seems like these all do the exact same thing. Obviously this is not the case, and if you 'href' when your supposed to 'src' your gonna have a bad time. But my question is, is there an easy way to remember which ones do which, and when they are used?
在编写 html/css 时,似乎这些都做完全相同的事情。显然,情况并非如此,如果您在应该 'src' 时使用 'href',您会过得很不愉快。但我的问题是,是否有一种简单的方法可以记住哪些是做什么的,以及何时使用?
回答by awiebe
src-- I want to load up this resource for myself.
src-- 我想为自己加载这个资源。
href-- I want to refer to this resource for someone else.
href- 我想为其他人参考此资源。
url-- A script wants to use this url as a variable.
url-- 一个脚本想要使用这个 url 作为变量。
回答by behnam
- In CSS, it's always
url
. - In HTML:
- It's
href
(short for Hypertext REFerence) for all kinds of links, including tagsa
andlink
. - When it's not a link, you are setting the source, so it's
src
.
- It's
- 在CSS 中,它总是
url
. - 在HTML 中:
- 它
href
(Hypertext REFerence的缩写)适用于各种链接,包括标签a
和link
. - 当它不是链接时,您正在设置source,因此它是
src
.
- 它
回答by Rohit Azad
it's very simple
这很简单
you can use href
for links as follows:<a href="http://www.google.com/">Click here</a>
<link href="mystylesheet.css" type="text/css">
您可以使用href
以下链接:<a href="http://www.google.com/">Click here</a>
<link href="mystylesheet.css" type="text/css">
Now use to src
put the links into html like this:<img src="mypic.jpg">
<script src="script.js"></script>
现在用于src
将链接放入 html 中,如下所示:<img src="mypic.jpg">
<script src="script.js"></script>