下面的代码是从ASP:Menu中的StaticItemTemplate生成的。
代码和链接可以随心所欲地执行,但是它无法通过验证。
输出代码如下
<li>
<a class="level1 StaticMenuItemStyle" href="/Services.aspx">
<div class="StaticMenuItemStyle"
onmouseover="style.backgroundColor='#0088CB';style.color=white;"
onmouseout="style.backgroundColor='';"
style="color:Color [Blue];width:180px;">
<a href="/Services.aspx" class="StaticMenuItemStyle">Services</a>
<br />
<div style="background-color: Blue; width: 180px;height: 5px;"></div>
</div>
</a>
</li>
但是W3验证器上的此错误
Line 84, Column 63: document type does not allow element "div" here; missing one of
"object", "ins", "del", "map", "button" start-tag
style="color:Color [Blue];width:180px;">
The mentioned element is not allowed to appear in the context in which you've placed
it; the other mentioned elements are the only ones that are both allowed there and
can contain the element mentioned. This might mean that you need a containing
element, or possibly that you've forgotten to close a previous element.
One possible cause for this message is that you have attempted to put a block-level
element (such as "<p>" or "<table>") inside an inline element (such as "<a>",
"<span>", or "<font>").
但是,如果我将 DIV 替换为跨度,它会验证。 但看起来不对。有人有任何想法如何解决这个问题吗?
在"a"标签中,div 不是验证的,因为div 基本上是一个块部分,默认样式是部分块。 http://webdesign.about.com/od/htmltags/a/aa011000a.htm。但是对于锚标签,它与span相同。您可以在div 属性上使用 onclick 属性,也可以使用 jquery 的 .click 函数。您可以像下面这样使用它:
<li>
<a class="level1 StaticMenuItemStyle" href="/Services.aspx">
<span class="StaticMenuItemStyle" style="display:block;"
onmouseover="style.backgroundColor='#0088CB';style.color=white;"
onmouseout="style.backgroundColor='';"
style="color:Color [Blue];width:180px;">
<a href="/Services.aspx" class="StaticMenuItemStyle">Services</a>
<br />
<div style="background-color: Blue; width: 180px;height: 5px;"></div>
</span>
</a> </li>
提到jquery在脚本之前初始化