猿吟鹤唳本无意,不知下有行人行

href与src的区别

 

SRC (Source)
src用于置换元素[1],即使说这个元素的内容通过src的地址获得,且不受css样式限制。比如

<script /> 
<img /> 
<video /> 
<object />

等。浏览器在解析到此处时会暂停所有渲染,加载直到此处内容被加载完成。
所以建议<script>放置在页面底端。比如:

<script src="dom1.js"></script>

HREF (HyperText Reference)
href 用于建立链接关系,比如

<a>, <link>

元素,浏览器在解析到此处时之道这里是个外部链接(或锚点)而并不需要加载这个链接的内容。因此页面解析不会被暂停。比如:

<a href="#yourAnchor">Click me</a>
URL (Uniform Resource Locator)
狭义来讲,在这里url代表了CSS的一个数据类型,它指定了一个数据的链接位置。通常的用法是用url()函数。比如

#your-element{
  background-image:url(http://placekitten.com/500/500);
}

There is a differentiation between src and href and they can’t be used interchangeably. We usesrc for replaced elements while href for establishing a relationship between the referencing document and an external resource.
href (Hypertext Reference) attribute specifies the location of a Web resource thus defining a link or relationship between the current element (in case of anchor a) or current document (in case of link) and the destination anchor or resource defined by this attribute. When we write:
The browser understands that this resource is a stylesheet and the processing parsing of the page isnot paused (rendering might be paused since the browser needs the style rules to paint and render the page). It is not similar to dumping the contents of the css file inside the style tag. (Hence is is advisable to use link rather than @import for attaching stylesheets to your html document.)
src (Source) attribute just embeds the resource in the current document at the location of the element’s definition. For eg. When the browser finds

The loading and processing of the page is paused until this the browser fetches, compiles and executes the file. It is similar to dumping the contents of the js file inside the script tag. Similar is the case with img tag. It is an empty tag and the content, that should come inside it, is defined by the src attribute. The browser pauses the loading until it fetches and loads the image. [so is the case with iframe]

引用
http://stackoverflow.com/questions/3395359/difference-between-src-and-href

发表评论

您的电子邮箱地址不会被公开。