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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:21:39  来源:igfitidea点击:

Differences between 'url', 'src', and 'href'

htmlcssurlhrefsrc

提问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

  1. In CSS, it's always url.
  2. In HTML:
    1. It's href(short for Hypertext REFerence) for all kinds of links, including tags aand link.
    2. When it's not a link, you are setting the source, so it's src.
  1. CSS 中,它总是url.
  2. HTML 中
    1. hrefHypertext REFerence的缩写)适用于各种链接,包括标签alink.
    2. 当它不是链接时,您正在设置source,因此它是src.

回答by Rohit Azad

it's very simple

这很简单

you can use hreffor 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 srcput 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>