對含有表單的網頁進行 XHTML 1.0 校驗時,發現無論如何也無法通過驗證,網上檢索了一下相關資料,發現有如下規則:
XHTML 1.0 Strict 中表單元素要放在<div></div>、<p></p>… 里面。
看下面的代碼:
<form method="post" action="">
<p>
<label>帳號 <input name="account" type="text" /></label>
<label>密碼 <input name="password" type="password" /></label>
<input type="submit" value="登錄" />
</p>
</form>
另外,如果 form 中包含 fieldset 元素,它可不必包含在 div、p 等元素中,但未包含在 fieldset 元素中的表單元素,必須包含在 div、p 中。
<form method="post" action="">
<fieldset>
<legend>帳戶</legend>
<label>帳號 <input name="account" type="text" /></label>
<label>密碼 <input name="password" type="password" /></label>
</fieldset>
<p><input type="submit" value="登錄" /></p>
</form>