src和herf的區別

src是連接,屬於總體替換(替換非疊加),好比img標籤和frame標籤;href是超文本引用,屬於附屬資源,能夠疊加。
再從html,css和js的關係來思考一下。html至關於人的身體(結構),css至關於衣服(樣式),js至關於動做(行爲)。想象一我的的生活,一件襯衫(css)能夠搭配不一樣的外套(即疊加href),而不是說買了一件襯衫(css)之後,就不穿任何一件外套了(即非總體替換src)。再好比說,小時候不會用筷子吃飯(行爲js),須要父母喂(行爲),而本身學會吃飯這一行爲之後,須要父母喂這一行爲就被徹底替換掉了(即src)。
 

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.css

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:html

<link href="style.css" rel="stylesheet" />

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.)ide

src (Source) attribute just embeds the resource in the current document at the location of the element's definition. For eg. When the browser findsfetch

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

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]this


Stack Overflow :html - Difference between SRC and HREFcode

相關文章
相關標籤/搜索