2008-10-31 34 views
2

任何想法,爲什麼這不會驗證此:爲什麼這個XHTML表單不會被驗證?

http://validator.w3.org/#validate_by_input

看來表單輸入標籤是錯誤的,但通過XHTML規範閱讀他們應該驗證罰款。有任何想法嗎?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Test</title> 
</head> 

<body> 
    <div class="Header"> 
     <table class="HeaderTable"> 
      <tr> 
       <td> 
        <div class="Heading">Test <span class="Standard">Test</span> 
        </div> 
       </td> 
       <td> 
        <div class="Controls"> 
         <form id="ControlForm" method="get" action="Edit.php"> 
          <input type="submit" name="action" id="Edit" value="Edit" /> 
          <input type="submit" name="action" id="New" value="New" /> 
         </form> 
        </div> 
       </td> 
      </tr> 
     </table> 
    </div> 
</body> 
</html> 

回答

3

你需要移動

<div class="Controls"> 

,以便它<形式標籤


這很好地

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Test</title> 
</head> 

<body> 
    <div class="Header"> 
     <table class="HeaderTable"> 
     <tr> 
      <td> 
       <div class="Heading">Test <span class="Standard">Test</span></div> 
      </td> 
      <td> 
       <form id="ControlForm" method="get" action="Edit.php"> 
        <div class="Controls"> 
         <input type="submit" name="action" id="Edit" value="Edit" /> 
         <input type="submit" name="action" id="New" value="New" /> 
        </div> 
       </form> 
      </td> 
     </tr> 
     </table> 
    </div> 
</body> 
</html> 
+2

爲了避免這個問題,我現在總是在每一個表格中使用

。 – 2010-04-13 19:03:05

5

嘗試在輸入周圍放置一個fieldset標籤。我想在XHTML形式的想法是,他們不能有直接後裔未div的,字段集等

+0

對。請注意,HTML5不再是這種情況:您可以將所有內容直接放在`form`中。 – 2014-08-02 13:18:27

3

正如別人所說的那樣:

[報價] 驗證器告訴你您隱藏的輸入元素不能立即跟隨表單標籤 - 它需要有某種類型的容器元素。 了[/ quote]

Source

我想一個字段可以幫助;見The XHTML DTD

<!ELEMENT form %form.content;> 

<!ENTITY % form.content "(%block; | %misc;)*"> 

<!ENTITY % misc "noscript | %misc.inline;"> 
<!ENTITY % misc.inline "ins | del | script"> 

<!ENTITY % block "p | %heading; | div | %lists; | %blocktext; | fieldset | table"> 

<!ENTITY % heading "h1|h2|h3|h4|h5|h6"> 
<!ENTITY % lists "ul | ol | dl"> 
<!ENTITY % blocktext "pre | hr | blockquote | address"> 

無輸入你:(

+0

謝謝,你是對的,輸入需要在一個排序的容器內。 – 2008-10-31 12:44:34

0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Test</title> 
</head> 

<body> 
    <div class="Header"> 
     <table class="HeaderTable"> 
       <tr> 
         <td> 
           <div class="Heading">Test <span class="Standard">Test</span> 
           </div> 
         </td> 
         <td> 

          <form id="ControlForm" method="get" action="Edit.php"> 
           <div class="Controls"> 
               <input type="submit" name="action" id="Edit" value="Edit" /> 
               <input type="submit" name="action" id="New" value="New" /> 
           </div> 
          </form> 

         </td> 
       </tr> 
     </table> 
    </div> 
</body> 
</html> 

驗證把你的DIV您的表單中。

0

您的輸入元素應位於字段集內。這證明並且具有使非文檔用戶代理更容易訪問文檔的附加好處。

另外,您的標記遭受divitis一點點。你可以直接在表格單元格上放置類,而不是在其中嵌套div元素(我不會評論使用表格進行佈局)。此外,您可以直接設計表單元素的樣式,而不是將其嵌套在div中。

總之,這裏的添加了一個字段的例子,令其驗證:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>Test</title> 
    </head> 
    <body> 
    <div class="Header"> 
     <table class="HeaderTable"> 
     <tr> 
      <td> 
      <div class="Heading">Test <span class="Standard">Test</span></div> 
      </td> 
      <td> 
      <div class="Controls"> 
       <form id="ControlForm" method="get" action="Edit.php"> 
       <fieldset> 
        <input type="submit" name="action" id="Edit" value="Edit" /> 
        <input type="submit" name="action" id="New" value="New" /> 
       </fieldset> 
       </form> 
      </div> 
      </td> 
     </tr> 
     </table> 
    </div> 
    </body> 
</html> 
1

我有同樣的問題,我花了一些時間來弄清楚。這是w3c驗證程序的最近更改嗎?這只是我確信我的一些頁面已經在過去被驗證過,但現在他們似乎都在爲同樣的問題解決錯誤。

以前我總是做這樣的事情:

<div> 
<form> 
    <label></label> 
    <input /> 
    <label></label> 
    <input /> 
    <label></label> 
    <input /> 
</form> 

,並得到驗證錯誤,所以現在我只需要添加字段集或DIV周圍所有的標籤和輸入得到它來驗證,這樣:

<div> 
<form> 
    <fieldset>or<div> 
     <label></label> 
     <input /> 
     <label></label> 
     <input /> 
     <label></label> 
     <input /> 
    </fieldset>or</div> 
</form> 

似乎工作,但我敢肯定,我沒得在過去做這個......嗯?