为什么这个 UL 和内联 JS 在 HTML 验证期间给出错误?

发布于 2024-09-03 08:59:26 字数 2781 浏览 3 评论 0原文

我刚刚通过 w3c HTML 验证器运行了我正在处理的网站的主页,它返回了 3 个错误和 2 个警告。我查看了它们,但不明白为什么它们会引起问题。我已将它们粘贴在下面(我已删除 URL/字符串等,因为该网站尚未准备好公开)。顺便说一句,这正在针对 XHTML Transitional 进行验证。

UL 返回时出现以下错误: end tag for "ul" which is not finish

    <ul id='tabs'> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat1" class="tab1" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab1_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat2" class="tab2" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab2_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat3" class="tab3" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab3_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat4" class="tab4" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab4_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat5" class="tab5" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab5_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat6" class="tab6" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab6_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat7" class="tab7" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab7_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat8" class="tab8" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab8_text
            </span> 
        </a>
    </li> 
    </ul>
    

    对于内联 javascript,我得到2 个错误和 2 个警告都是针对同一件事 - 我有一个简单的 if 语句 &&并且验证器似乎将其视为 HTML 而不是 javascript: character "&amp;"是分隔符的第一个字符,但作为 dataxmlParseEntityRef: no name 出现。

    <script type='text/javascript'>
        if (weather_data != null && weather_data['data'] != null){
        display_weather();
    }
    </script>
    

    javascript 放置在文档末尾的正文关闭标记之前。 如果您需要查看完整来源,请告诉我,我可以将其发送给您。

    I've just run the homepage of a site I'm working on through the w3c HTML validator and it's come back with 3 errors and 2 warnings. I've taken a look at them but can't see why they would be causing a problem. I've pasted them in below (I've removed URL's/strings etc as the site isn't quite ready to be made public yet). This is being validated against XHTML Transitional by the way.

    The UL comes back with the following error: end tag for "ul" which is not finished <ul id='tabs'></ul>

    <ul id='tabs'> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat1" class="tab1" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab1_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat2" class="tab2" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab2_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat3" class="tab3" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab3_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat4" class="tab4" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab4_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat5" class="tab5" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab5_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat6" class="tab6" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab6_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat7" class="tab7" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab7_text
            </span> 
        </a>
    </li> 
    <li> 
        <a href="/en/folder/folder/search?categories[]=cat8" class="tab8" title="tab_title">
            <img alt="img_alt" src="img_src" /> 
            <span> 
                tab8_text
            </span> 
        </a>
    </li> 
    </ul>
    

    For the inline javascript, I'm getting 2 errors and 2 warnings all for the same thing - I have a simple if statement with && and the validator appears to be seeing this as HTML rather than javascript: character "&" is the first character of a delimiter but occurred as data and xmlParseEntityRef: no name

    <script type='text/javascript'>
        if (weather_data != null && weather_data['data'] != null){
        display_weather();
    }
    </script>
    

    The javascript is placed just before the body close tag at the end of the document.
    If you need to see the full source then let me know and I can send it over.

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(3

    此刻的回忆 2024-09-10 08:59:26

    XML 不支持固有的 CDATA,因此 & 符号在 XHTML 中具有特殊含义它们在 HTML 中没有,但您可能将 XHTML 作为文本/html 提供,因此请参阅 嵌入样式表和脚本

    至于:

    “ul”的结束标记尚未完成

    给定

    <ul id='tabs'></ul>
    

    列表中至少有一个列表项, 。我猜您正在使用 JavaScript 填充它(因此是您的第二个 ul 示例),但验证器并不关心这一点。

    XML doesn't support intrinsic CDATA so ampersands have special meaning in XHTML that they don't have in HTML, but you are probably serving your XHTML as text/html so see the compatibility guidelines for Embedded Style Sheets and Scripts

    As for:

    end tag for "ul" which is not finished

    given

    <ul id='tabs'></ul>
    

    A list has to at least one list item in it. I'm guessing that you are populating it with JavaScript (hence your second example of a ul), but the validator doesn't care about that.

    多像笑话 2024-09-10 08:59:26

    不确定 UL 问题,但您可能希望将 CDATA 放在脚本中。

    请参阅http://www.w3schools.com/xml/xml_cdata.asp

    Not sure about the UL problem, but you might want to put CDATA around your script.

    see http://www.w3schools.com/xml/xml_cdata.asp

    情仇皆在手 2024-09-10 08:59:26

    要验证内联 Javascript,您需要将内容包装在 CDATA 标记中,并添加 JS 注释,以使其验证:

    <script type='text/javascript'>
    //<![CDATA[
    if (weather_data != null && weather_data['data'] != null){
      display_weather();
    }
    //]]>
    </script>
    

    我检查了您在 W3C 验证器中发布的 HTML 列表片段,它已成功验证为 HTML 4.01 Strict< /em> 和 XHTML 1.0 严格。所以问题出在其他地方。您可以发布整个页面的链接吗?

    To validate the inline Javascript, you need to wrap the contents in CDATA tags, and add JS comments, to make it validate:

    <script type='text/javascript'>
    //<![CDATA[
    if (weather_data != null && weather_data['data'] != null){
      display_weather();
    }
    //]]>
    </script>
    

    I checked the HTML list fragment you posted in the W3C validator and it validated successfully as HTML 4.01 Strict and XHTML 1.0 Strict. So the problem is somewhere else. Can you post a link to your entire page?

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文