我的网站菜单结构包含查询字符串,显然包含&
符号。完整菜单HTML是
<div id="menu">
<ul>
<li><a href="~/Products.aspx?Gender=Male" class="inactive" runat="server">Men</a>
<ul>
<li><a href="~/Products.aspx?Gender=Male&Type=Coats" runat="server">Coats</a></li>
<li><a href="~/Products.aspx?Gender=Male&Type=Jeans" runat="server">Jeans</a></li>
<li><a href="~/Products.aspx?Gender=Male&Type=Knitwear" runat="server">Knitwear</a></li>
<li><a href="~/Products.aspx?Gender=Male&Type=Shoes" runat="server">Shoes</a></li>
<li><a href="~/Products.aspx?Gender=Male&Type=T-Shirts" runat="server">T-Shirts</a></li>
</ul>
</li>
<li><a href="~/Products.aspx?Gender=Female" class="inactive" runat="server">Women</a>
<ul>
<li><a href="~/Products.aspx?Gender=Female&Type=Coats" runat="server">Coats</a></li>
<li><a href="~/Products.aspx?Gender=Female&Type=Jeans" runat="server">Jeans</a></li>
<li><a href="~/Products.aspx?Gender=Female&Type=Knitwear" runat="server">Knitwear</a></li>
<li><a href="~/Products.aspx?Gender=Female&Type=Shoes" runat="server">Shoes</a></li>
<li><a href="~/Products.aspx?Gender=Female&Type=T-Shirts" runat="server">T-Shirts</a></li>
</ul>
</li>
<li><a href="~/Products.aspx?Gender=Kids" class="inactive" runat="server">Kids</a>
<ul>
<li><a href="~/Products.aspx?Gender=Kids&Type=Coats" runat="server">Coats</a></li>
<li><a href="~/Products.aspx?Gender=Kids&Type=Jeans" runat="server">Jeans</a></li>
<li><a href="~/Products.aspx?Gender=Kids&Type=Knitwear" runat="server">Knitwear</a></li>
<li><a href="~/Products.aspx?Gender=Kids&Type=Shoes" runat="server">Shoes</a></li>
<li><a href="~/Products.aspx?Gender=Kids&Type=T-Shirts" runat="server">T-Shirts</a></li>
</ul>
</li>
<li><a href="~/Stores.aspx" runat="server">Stores</a></li>
<li><a href="~/Contact.aspx" runat="server">Contact</a></li>
</ul>
</div>
正如您所看到的,我已经正确地逃过了&符号。但是,当我通过W3C验证器运行页面时,我得到15个错误,说...
&安培;没有开始角色参考。 (并且可能应该已经作为&amp; amp;扩展了。)
这15个错误适用于&amp;放大器;在我的HTML中。有什么建议?谢谢。
答案 0 :(得分:0)
忽略runat
属性(HTML中不允许),您的代码是有效的HTML5。
您已使用&
正确转义了&
的网址。您引用的错误不是由您的问题中的代码引起的。
您可以使用the W3C validator检查的最小示例:
<!DOCTYPE html>
<html lang="en">
<head><title>Example</title></head>
<body>
<a href="~/Products.aspx?Gender=Kids&Type=Coats">Coats</a>
</body>
</html>
答案 1 :(得分:0)
使用ASP.NET超链接控件而不是标准HTML
解决<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Products.aspx?Gender=Male&Type=Coats">Coats</asp:HyperLink></li>