0

验证站点时,我收到以下错误附加到多个图像:

一个 img 元素必须有一个 alt 属性,除非在某些情况下。有关详细信息,请参阅有关为图像提供替代文本的指南。

尽管我在代码中包含了 alt 标签,但还是会出现这种情况:

<nav>
        <ul>
            <li><a href="index.php?page_id=7"><img src="<?php bloginfo('url'); ?>"><img src="<?php echo get_template_directory_uri(); ?>/img/about.png" alt="about%20Z" /></a>
                <ul class="about">
                    <li><a href="index.php?page_id=35">ZR</a> |</li>
                    <li><a href="index.php?page_id=38"> RA</a> |</li>
                    <li><a href="index.php?page_id=40"> WM + SB</a> |</li>
                    <li><a href="index.php?page_id=42"> ZV</a></li>
                </ul><!-- end subs -->
            <li><a href="index.php?page_id=16"><img src="<?php bloginfo('url'); ?>"><img src="<?php echo get_template_directory_uri(); ?>/img/blog.png" alt="ZB" /></a></li>
            <li><a href="index.php?page_id=13"><img src="<?php bloginfo('url'); ?>"><img src="<?php echo get_template_directory_uri(); ?>/img/share.png" alt="swZ" /></a></li>
            <li><a href="index.php?page_id=9"><img src="<?php bloginfo('url'); ?>"><img src="<?php echo get_template_directory_uri(); ?>/img/contact.png" alt="cZ" /></a></li>
            <li><a href="http://www.thezopateam.com/"><img src="<?php bloginfo('url'); ?>"><img src="<?php echo get_template_directory_uri(); ?>/img/properties.png" alt="ZP" /></a>
                <ul class="properties">
                    <li><a href="http://www.thezopateam.com/">Buying</a> |</li>
                    <li><a href="index.php?page_id=46"> Selling</a></li>
                </ul><!-- end subs -->
            <li><a href="index.php?page_id=11"><img src="<?php bloginfo('url'); ?>"><img src="<?php echo get_template_directory_uri(); ?>/img/gallery.png" alt="Zg" /></a></li>
        </ul>
    </nav>

有什么想法可能导致这种情况/如何补救?谢谢。

4

4 回答 4

3

在您的代码中,您似乎首先在内部缺少该alt属性<img><a>

<li>
   <a href="index.php?page_id=7">
      <img src="<?php bloginfo('url'); ?>"> <!-- Missing Alt Attribute -->
      <img src="<?php echo get_template_directory_uri(); ?>/img/about.png" alt="about%20Z" />
   </a>
...

大约有 6 个<img>标签没有alt属性

于 2012-10-26T20:41:28.137 回答
2

如果您选中“选项”下的“显示源”,然后单击重新验证,您将能够准确看到这些问题的位置。

于 2012-10-26T20:35:46.790 回答
0

每个<img>标签都必须有一个alt属性。验证器应该准确地告诉您哪些图像(哪些行)缺少alt属性。Alt 属性为那些看不到/解析图像的人提供了图像的上下文(想想谷歌)。

很难确定(因为您提供的是 PHP,而不是 HTML),但看起来这些中的每一个<img src="<?php bloginfo('url'); ?>">都缺少alt属性。

于 2012-10-26T20:43:19.513 回答
0

这些错误与缺少 alt 标签无关(因为它们在那里),而是由我的 php.ini 中的错误触发。修复了错误,页面验证。

于 2012-10-26T20:48:26.567 回答