0

下面的代码是从 ASP:Menu 中的 StaticItemTemplate 生成的。

代码和链接随心所欲,但验证失败。

输出代码如下

<li>
    <a class="level1 StaticMenuItemStyle" href="/Services.aspx">
    <div class="StaticMenuItemStyle"
         onmouseover="style.backgroundColor=&#39;#0088CB&#39;;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>

但是 W3Validator 上的这个错误

  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。但看起来不对。有人知道如何解决这个问题吗?

4

1 回答 1

0

在“a”标签内,div 是不验证的,因为 div 基本上是一个块部分,默认样式是部分块。http://webdesign.about.com/od/htmltags/a/aa011000a.htm。但是对于锚标签,它与跨度相同。您可以在 div 属性上使用 onclick 属性,也可以通过 jquery 使用 .click 函数。你可以像下面这样使用它:

<li>
    <a class="level1 StaticMenuItemStyle" href="/Services.aspx">
    <span class="StaticMenuItemStyle" style="display:block;" 
         onmouseover="style.backgroundColor=&#39;#0088CB&#39;;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是在脚本之前初始化的

于 2012-08-13T19:29:50.030 回答