简体   繁体   English

在自定义ASP:Menu中使用DIVS时无法验证

[英]DIVS not validating when used in a custom ASP:Menu

My Code below is generated from a StaticItemTemplate in an ASP:Menu. 我下面的代码是从ASP:Menu中的StaticItemTemplate生成的。

The code and the link does as it pleases, however it fails validation. 代码和链接可以随心所欲,但是验证失败。

Output code is as follows 输出代码如下

<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>

however this errors on W3Validator 但是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>").

However if i replace the DIV with a span it validates. 但是,如果我用跨度替换DIV,则可以验证。 but doesnt look right. 但看起来不正确。 Anyone got any ideas how to get round this ? 任何人都知道如何解决这个问题?

Inside a "a" tag, div is not validate, because div is a basically block section and default style is section block. 在“ a”标签中,div是无效的,因为div是一个基本上是块的节,而默认样式是节块。 http://webdesign.about.com/od/htmltags/a/aa011000a.htm. http://webdesign.about.com/od/htmltags/a/aa011000a.htm。 But for anchor tag, it is same like as span. 但是对于锚标记,它与span相同。 You can use onclick attribute on the div attribute or use .click function by jquery. 您可以在div属性上使用onclick属性,也可以通过jquery使用.click函数。 You can use it like below: 您可以如下使用它:

<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>

Mention the jquery is initialize before the script 提到在脚本之前初始化jQuery

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

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