为什么这个 UL 和内联 JS 在 HTML 验证期间给出错误?
我刚刚通过 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 "&"是分隔符的第一个字符,但作为 data
和 xmlParseEntityRef: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
XML 不支持固有的 CDATA,因此 & 符号在 XHTML 中具有特殊含义它们在 HTML 中没有,但您可能将 XHTML 作为文本/html 提供,因此请参阅 嵌入样式表和脚本
至于:
给定
列表中至少有一个列表项, 。我猜您正在使用 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:
given
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.不确定 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
要验证内联 Javascript,您需要将内容包装在 CDATA 标记中,并添加 JS 注释,以使其验证:
我检查了您在 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:
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?