img标签data-src和src的区别,img的data-src属性实现懒加载代码区别

2022-01-23
0评论
/
1092阅读
爱搜啊

更新过最新的图片懒加载,发现里面原来的img标签src属性名称更改为data-src,那么data-src到底与原来的src有什么不同呢?

data-src是html5的新属性,意思是数据来源。

date-src应该是data-src意思是指定数据绑定时的数据源的ID。

列:数据来源<a href="#" data-src="zhidao.baidu.com/question/2012105519870230508.html?entry=qb_ihome_tag">

数据绑定时的数据源的ID<img data-src="#XMLobj" datafld="url" />

这里推荐下解决SEO问题(搜索引擎无法获取真实图片地址)的懒加载方法《图片懒惰加载-无SEO负面影响解决搜索引擎无法获取真实src图片地址

img标签data-src和src的区别

问题描述

使用 data-src 或 src 属性的差异和后果(无论是好还是坏) img 标记?我可以使用两者达到相同的结果吗?如果是这样,什么时候应该使用它们中的每一个? 属性 src 和 data-src 没有任何共同之处,除了它们都被HTML5 CR所允许并且它们都包含字母 src 。其他的都不一样。 

src 属性在HTML规范中定义,它有一个功能含义。 / p> 

data-src 属性只是数据的无限集合之一 - * 属性,它们没有定义的含义,但可用于在元素中包含不可见的数据,以用于脚本(或样式)。

What are differences and consequences (both good and bad) of using either data-src or src attribute of img tag? Can I achieve the same results using both? If so, when should be used each of them?

解决方案

The attributes src and data-src have nothing in common, except that they are both allowed by HTML5 CR and they both contain the letters src. Everything else is different.

The src attribute is defined in HTML specs, and it has a functional meaning.

The data-src attribute is just one of the infinite set of data-* attributes, which have no defined meaning but can be used to include invisible data in an element, for use in scripting (or styling).


本站附件分享,如果附件失效,可以去找找看

诚通网盘附件百度网盘附件


于2022-01-23发布