【问题标题】:Is <img src="[srcpath]" alt=""> the same as <img src="[srcpath]" alt> when it comes to accessibility?<img src="[srcpath]" alt=""> 在可访问性方面是否与 <img src="[srcpath]" alt> 相同?
【发布时间】:2014-12-09 15:34:39
【问题描述】:
<img src="[srcpath]" alt="">
<img src="[srcpath]" alt>

也就是说:

图像alt 文本是否都被视为空值?还是必须确保alt="" 存在?

【问题讨论】:

    标签: html accessibility alt


    【解决方案1】:

    应该使用alt="" 属性。 specs for providing alternative text for an image 中的每个空 alt 属性示例都明确使用它。这里是another resource on the empty alt="" attribute

    但是.. 如果我查看 Chrome 中的 DOM 检查器并查看源代码中包含 alt=""img,我会看到 &lt;img src="[srcpath]" alt&gt;

    WCAG 2.0 标准中的Failure Criterion F65 指出,寻找alt 属性的存在。它没有说明对于 HTML5 标准是否必须将 alt 属性显式声明为空 (alt=""),并且只要您是 using the HTML according to the spec,从技术上讲,拥有 &lt;img src="[srcpath]" alt&gt; 将被认为是可访问的。

    总而言之 - 是的,就可访问性而言,它们在技术上是相同的,但我不是一个从给定指令中获得的人。通过使用alt="",您将了解alt 属性的用途,并在HTML 规范方面保持您的alt 技术的一致性。

    【讨论】:

    • 谢谢@sjagr - 我的问题源于这样一个事实,即我通过 javascript 将 alt 属性设置为“”在 chrome 检查器中呈现为简单的“alt”,这让我感到困惑。
    • @Abaxis 作为开发人员,我会说 Chrome 在使用 alt="" 或使用 Javascript 将 alt 属性设置为 alt="" 正确完成工作后所做的任何事情范围和用户代理的负担!
    【解决方案2】:

    两者都有 空字符串 作为值,所以它们是等价的。

    HTML5 定义了attributes can be specified in four different ways,其中“空属性语法”:

    只是属性名称。该值隐含为空字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-28
      • 2021-02-12
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      相关资源
      最近更新 更多