简体   繁体   English

为什么该UL和内联JS在HTML验证期间出现错误?

[英]Why is this UL and inline JS giving errors during HTML validation?

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. 我刚刚通过w3c HTML验证程序运行了一个正在工作的网站的主页,并且返回了3个错误和2个警告。 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). 我将它们粘贴在下面(我已经删除了URL /字符串等,因为该网站尚未准备好公开)。 This is being validated against XHTML Transitional by the way. 顺便说一下,这已经针对XHTML Transitional进行了验证。

The UL comes back with the following error: end tag for "ul" which is not finished <ul id='tabs'></ul> UL返回以下错误: 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 "&amp;" is the first character of a delimiter but occurred as data 对于内联javascript,我在同一件事上都收到2个错误和2个警告-我有一个简单的if语句,其中包含&&和验证程序似乎将其视为HTML而不是javascript: character "&amp;" is the first character of a delimiter but occurred as data character "&amp;" is the first character of a delimiter but occurred as data and xmlParseEntityRef: no name character "&amp;" is the first character of a delimiter but occurred as dataxmlParseEntityRef: 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. javascript放在文档结尾处body close标记之前。 If you need to see the full source then let me know and I can send it over. 如果您需要查看完整的源代码,请告诉我,我可以将其发送出去。

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 XML不支持固有的CDATA,因此在XHTML中,“ &”号在HTML中没有特殊的含义 ,但是您可能将XHTML作为text / html来使用,因此请参阅嵌入式样式表和脚本的兼容性指南。

As for: 至于:

end tag for "ul" which is not finished 尚未结束的“ ul”的结束标签

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. 我猜想您正在用JavaScript填充它(因此是ul第二个示例),但是验证器对此并不在意。

Not sure about the UL problem, but you might want to put CDATA around your script. 不确定UL问题,但您可能希望将CDATA放在脚本中。

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

To validate the inline Javascript, you need to wrap the contents in CDATA tags, and add JS comments, to make it validate: 要验证内联Javascript,您需要将内容包装在CDATA标记中,并添加JS注释,以使其有效:

<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 . 我检查了您在W3C验证器中发布的HTML列表片段,它已成功验证为HTML 4.01 StrictXHTML 1.0 Strict So the problem is somewhere else. 所以问题出在别的地方。 Can you post a link to your entire page? 您可以发布指向整个页面的链接吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM