對含有表單的網(wǎng)頁進行 XHTML 1.0 校驗時,發(fā)現(xiàn)無論如何也無法通過驗證,網(wǎng)上檢索了一下相關(guān)資料,發(fā)現(xiàn)有如下規(guī)則:
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>