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.

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:

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

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

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

Stack Overflow :html - Difference between SRC and HREF

时间: 2024-08-30 18:10:00

src和herf的区别的相关文章

【android】ImageView的src和background的区别以及两者的妙用

一.ImageView中XML属性src和background的区别: background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸 .src是图片内容(前景),bg是背景,可以同时使用. 此外: scaleType只对src起作用:bg可设置透明度,比如在ImageButton中就可以用android:scaleType控制图片的缩放方式 二. 解决android:background背景图片被拉伸问题 : 如上所述,background设置的

ImageView的src和background的区别

参考资料: http://blog.csdn.net/dalleny/article/details/14048375 http://www.android100.org/html/201508/27/177067.html 区别如下: 1.  background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸,如果想要对src进行拉伸的话,使用android:scaleType 2.  src是图片内容(前景),bg是背景,可以同时使用. 3.  此

android中src和background的区别

ImageView中XML属性src和background的区别: background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸.src是图片内容(前景),bg是背景,可以同时使用. 此外:scaleType只对src起作用:bg可设置透明度,比如在ImageButton中就可以用android:scaleType控制图片的缩放方式,示例代码如下: <ImageView android:id="@+id/img"     andr

浅析src与href的区别

src与href的区别 SRC src用于替换当前元素,href用于在当前文档和引用资源之间确立联系. src是source的缩写,指向外部资源的位置,指向的内容将会嵌入到文档中当前标签所在位置:在请求src资源时会将其指向的资源下载并应用到文档内,例如js脚本,img图片和iframe等元素. 举例: script元素:<script src ="js.js"></script> 当浏览器解析到该元素时,会暂停其他资源的下载和处理,直到将该资源加载.编译.执行

CSS_url 、src 、href 的区别

url.href.src 区别 URL(Uniform Resource Locator) 统一资源定位符是对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网上标准资源的地址.互联网上的每个文件都有一个唯一的URL,它包含的信息指出文件的位置以及浏览器应该怎么处理它. 结构 基本URL包含模式(或称协议).服务器名称(或IP地址).路径和文件名,如“协议://授权/路径?查询”.完整的.带有授权部分的普通统一资源标志符语法看上去如下:协议://用户名:密码@子域名.域名.顶级域

html中的src与href的区别

写代码的时候就经常把这两个属性弄混淆,到底是href还是src,href标识超文本引用,用在link和a等元素上,href是引用和页面关联,是在当前元素和引用资源之间建立联系,src表示引用资源,表示替换当前元素,用在img,script,iframe上,src是页面内容不可缺少的一部分. src是source的缩写,是指向外部资源的位置,指向的内部会迁入到文档中当前标签所在的位置:在请求src资源时会将其指向的资源下载并应用到当前文档中,例如js脚本,img图片和frame等元素. <scri

关于src与href的区别

src和href之间存在区别,能混淆使用.src用于替换当前元素,href用于在当前文档和引用资源之间确立联系. src和href之间存在区别,能混淆使用.src用于替换当前元素,href用于在当前文档和引用资源之间确立联系. src是source的缩写,指向外部资源的位置,指向的内容将会嵌入到文档中当前标签所在位置:在请求src资源时会将其指向的资源下载并应用到文档内,例如js脚本,img图片和frame等元素. <script src ="js.js"></scr

src和href的区别

href和src是有区别的,而且是不能相互替换的.我们在可替换的元素上使用src,然而把href用作子啊涉及的文档和外部资源之间建立一个关系.   href(hypertext Reference)指定网络资源的位置,从而在当前文档和由当前属性定义的需要的锚点或资源之间定义要给链接或者关系.当我们写下 <link href=“index.css” rel=“stylesheet”> 浏览器就会明白当前的资源是一个样式表,页面解析不会暂停(因为浏览器需要样式规则去画或者渲染页面,渲染过程可能会被

src与href的区别

src是source的缩写,指向外部资源的位置,指向的内容将会嵌入到文档中当前标签所在的位置.在请求src资源时会将其指向的资源下载并应用到文档中.如js脚本.img图片和frame等元素. <script src=".js"></script>当浏览器解析到该元素时,会暂停其他资源的下载和处理,直到该元素加载.编译和执行结束.因此js脚本应放在底部而非头部. href是hypertext reference的缩写.指向网络资源所在的位置.用于在当前文档与引用资