2010-10-22 36 views
1

我有與W3驗證程序驗證此代碼的問題。 問題出在<form>標籤上。 我需要<form>標記重疊幾個<div><span>標記,因爲我有許多不同的輸入字段等,但我也使用Form2和Form3與輸入字段等,所以我需要在Form2之前使用</form>。但這在驗證時會給我帶來問題,因爲它與<div><span>標記重疊。 我該如何做驗證工作?W3C驗證問題與重疊窗體和div標籤

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html lang="sv" xml:lang="sv" xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
    <title>Title</title> 
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" /> 
</head> 
<body> 
<div id="wrapper"> 

<div id="headerwrapper"> 
    <div class="header alignleft"> 
    <a href="index.html">Home</a> 
    </div> 
    <div class="header alignright"> 
    <div id="searchfield"> 
    Search 
    </div> 
    </div> 

    <div id="menu"> 
    Menu 
    </div> 
</div> 
<div class="clear"></div> 

<div class="content"> 
    <div class="box alignleft"> 

    <div class="boxtop"></div> 
    <div class="boxmiddle"> 

    <form action="links.php" method="post"><input type="hidden" name="edit_page_check" value="yes" /> 

    <p> 
    <span id="page_leftbox">Text</span> 
    </p> 
    </div> 

    <div class="boxbottom"></div> 

    </div> 
    <div class="column580 alignright"> 

    <div class="header580"> 
    <h2>Topic</h2><span class="headerdesc">Text</span> 
    </div> 
    <p> 

    <span id="page_info">Info</span> 

    </p> 

    </form> 
    <br/> 
    <div id="addlinkform" style="display: none;"> 
Form2 
    </div> 
    <div id="linkform" style="display: none;"> 
Form3 
    </div> 
    </div> 
</div> 
<div class="clear"></div> 
<div class="divider800"></div> 
<div id="footer"> 
Footer text 
</div> 
</div> 
</body> 
</html> 
+0

您放入問題中的所有示例標籤都被顯示處理器剝離。如果他們被轉義出來或以某種方式顯示出來,這個問題將會變得更加清晰 - 將它們包裹在字符(代碼塊)中可能會有所幫助。 – pjmorse 2010-10-22 18:56:33

+0

@pjmorse:我解決了這個問題。 – jwueller 2010-10-22 18:59:39

回答

0

XML(在這種情況下是XHTML)需要格式良好。看看this。您應該能夠通過在樹中移動<form> -tag來解決該問題。

而不是

<div> 
    <form action="/some_target" method="post"> 
     <input/> 
</div> 
<div> 
     <input /> 
    </form> 
</div> 

執行以下操作(移動form元素了,所以它封裝了輸入以及它們的容器):

<form action="/some_target" method="post"> 
    <div> 
     <input/> 
    </div> 
    <div> 
     <input /> 
    </div> 
</form> 
2

XHTML不會讓你重疊標籤。例如,這是無效的:

<div><form></div></form> 

什麼你會想要做的是,而不是試圖只包括您認爲在形式,涵蓋<input />標記,都在表格中的項目以及其容器。例如,您的代碼應該如下所示:

<div class="content"> 
    <form action="links.php" method="post"><input type="hidden" name="edit_page_check" value="yes" /> 
    <div class="box alignleft"> 

    <div class="boxtop"></div> 
    <div class="boxmiddle"> 


    <p> 
    <span id="page_leftbox">Text</span> 
    </p> 
    </div> 

    <div class="boxbottom"></div> 

    </div> 
    <div class="column580 alignright"> 

    <div class="header580"> 
    <h2>Topic</h2><span class="headerdesc">Text</span> 
    </div> 
    <p> 

    <span id="page_info">Info</span> 

    </p> 

    <br/> 
    <div id="addlinkform" style="display: none;"> 
Form2 
    </div> 
    <div id="linkform" style="display: none;"> 
Form3 
    </div> 
    </div> 
    </form> 
</div> 

請注意表單元素如何跨越所有輸入標記的容器。