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

相关文章
相关标签/搜索