HTML 5 <form> 標(biāo)簽
定義和用法
<form> 標(biāo)簽創(chuàng)建供用戶輸入的表單。
表單可包含文本域,復(fù)選框,單選按鈕等等。表單用于向指定的 URL 傳遞用戶數(shù)據(jù)。
HTML 4.01 與 HTML 5 之間的差異
在 HTML 5 中有一些新屬性,同時(shí)不再支持 HTML 4.01 中的一些屬性。
在 HTML 5 中有一個(gè)新屬性:replace。它定義表單被提交后所做的事情。
屬性
屬性 | 描述 | 4 | 5 |
---|---|---|---|
action | 定義一個(gè) URL。當(dāng)點(diǎn)擊提交按鈕時(shí),向這個(gè) URL 發(fā)送數(shù)據(jù)。 | 4 | 5 |
data | 供自動(dòng)插入數(shù)據(jù)。 | ? | 5 |
replace | 定義表單提交時(shí)所做的事情。 | ? | 5 |
accept | 處理該表單的服務(wù)器可正確處理的內(nèi)容類型列表(用逗號(hào)分隔)。 | 4 | 5 |
accept-charset | 表單數(shù)據(jù)的可能的字符集列表(逗號(hào)分隔)。默認(rèn)值是 "unknown"。 | 4 | 5 |
enctype | 用于對(duì)表單內(nèi)容進(jìn)行編碼的 MIME 類型。 | 4 | 5 |
method | 用于向 action URL 發(fā)送數(shù)據(jù)的 HTTP 方法。默認(rèn)是 get。 | 4 | 5 |
name | 為表單定義一個(gè)唯一的名稱。不支持。用 id 代替。 | 4 | ? |
target | 在何處打開(kāi)目標(biāo) URL。 | 4 | 5 |
標(biāo)準(zhǔn)屬性
class, contenteditable, contextmenu, dir, draggable, id, irrelevant, lang, ref, registrationmark, tabindex, template, title
如需完整的描述,請(qǐng)?jiān)L HTML 5 中標(biāo)準(zhǔn)屬性。
事件屬性
onabort, onbeforeunload, onblur, onchange, onclick, oncontextmenu, ondblclick, ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop, onerror, onfocus, onkeydown, onkeypress, onkeyup, onload, onmessage, onmousedown, onmousemove, onmouseover, onmouseout, onmouseup, onmousewheel, onresize, onscroll, onselect, onsubmit, onunload
如需完整的描述,請(qǐng)?jiān)L HTML 5 中事件屬性。
TIY 實(shí)例
- 帶有輸入框和確認(rèn)按鈕的表單
- 本例演示如何向頁(yè)面添加表單。此表單包含兩個(gè)輸入框和一個(gè)確認(rèn)按鈕。
- 帶有復(fù)選框的表單
- 此表單包含兩個(gè)復(fù)選框和一個(gè)確認(rèn)按鈕。
- 帶有單選按鈕的表單
- 此表單包含兩個(gè)單選框和一個(gè)確認(rèn)按鈕。
- 從表單發(fā)送電子郵件
- 此例演示如何從表單發(fā)送電子郵件。