对于动态生成的img src,“元素img上的属性src的错误值:必须非空” [英] "Bad value for attribute src on element img: Must be non-empty", for dynamically generated img src

查看:982
本文介绍了对于动态生成的img src,“元素img上的属性src的错误值:必须非空”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像滑块的网站。当幻灯片进入视图以加快页面加载时,我会将一些图像标记保留为空,以便加载图像。图片标签定义如下:

 < img data-src =img / portfolio-desktop1-small.pngsrc =alt =/> 

我正在做的是在幻灯片函数中我改变 src data-src 与jQuery动画。滑块效果很好。我的问题是当我尝试在 w3c验证工具中验证它时,它提供了以下错误:


第131行,第179列:元素 img上属性 src 的值不正确

网址的语法:

任何网址。例如: / hello #canvas http://example.org/ 。 >字符应该用NFC表示,空格应该转义为%20




<无论如何要修改这个,而不改变JavaScript或CSS?如果我把它放在这里,可能会造成这种事情的有害后果吗?

解决方案

如果你只是删除src属性,然后在需要时随时添加。 src属性不是必需的。在我看来,我不会担心无论如何w3c验证工具说。只要您在必要的浏览器中进行测试并且它可以正常工作。

I have a web site with an image slider. I keep the some of the image tags empty as the images load on when slide comes into view for faster page load. The image tags defined as follows:

<img data-src="img/portfolio-desktop1-small.png" src="" alt=""/>

What I'm doing is on slide function I change the src to data-src with jQuery animation. The slider works great. My problem is when I try to validate it in w3c validation tool it gives the following error:

Line 131, Column 179: Bad value for attribute src on element img: Must be non-empty.

...data-src="img/portfolio-desktop1-small.jpg" src="" alt=""/>

Syntax of URL:
Any URL. For example: /hello, #canvas, or http://example.org/. > Characters should be represented in NFC and spaces should be escaped as %20.

Is there anyway to fix this without altering the JavaScript or CSS? If I leave it like this what can be the possible harmful outcomes of this matter?

解决方案

What happens if you just remove the src attribute then add it on the fly when you need it. The src attribute isn't required. And in my opinion I wouldn't worry about what the w3c validation tool says anyway. As long as you test it in the necessary browsers and it works.

这篇关于对于动态生成的img src,“元素img上的属性src的错误值:必须非空”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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