如何使用data-src和src? [英] How to use data-src and src?

查看:285
本文介绍了如何使用data-src和src?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 src data-src 来显示图像时遇到问题 img 标记。

I am encountering a problem with getting an image to display with the usage of src and data-src of the img tag.

下面的工作非常好:

The below work perfectly fine:

<img src = "img/testimage1.jpg"/>

以下代码不会显示任何内容:

The below code doesn't display anything:

<img data-src = "img/testimage1.jpg" alt="first"/>


推荐答案

已经在这里回答了 data-src 是一个简单的 data - * 属性的HTML5规范,而 src 定义图片标签的来源。

As already answered here, data-src is a simple data-* attribute of the HTML5 spec, while src defines the source of the image tag.

data - * 属性只对JS脚本有意义。

data-* attributes only have meaning for JS scripts.

这篇关于如何使用data-src和src?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆