自: http://www.runoob.com
標籤定義及使用說明
<input> 標籤規定了使用者可以在其中輸入資料的輸入欄位。
<input> 元素在 <form> 元素中使用,用來宣告允許使用者輸入資料的 input 控制元件。
輸入欄位可通過多種方式改變,取決於 type 屬性。
提示和註釋
注意: <input> 元素是空的,它只包含標籤屬性。
提示: 你可以使用 <label> 元素來定義 <input> 元素的標註。
HTML 4.01 與 HTML5之間的差異
在 HTML 4.01 中, "align" 資料已經不再使用。HTML5 中不支援該屬性。 可以使用CSS來定義 <input> 元素的對齊方式。
在 HTML5中, <input> 添加了幾個屬性,並且添加了對應的值。
HTML 與 XHTML 之間的差異
在 HTML 中,<input> 標籤沒有結束標籤。
在 XHTML 中,<input> 標籤必須被正確地關閉。
屬性
New : HTML5新標籤。
屬性 | 值 | 描述 |
---|---|---|
accept | audio/* video/* image/* MIME_type | 規定通過檔案上傳來提交的檔案的型別。 (只針對type="file") |
align | left right top middle bottom | HTML5已廢棄,不贊成使用。規定影象輸入的對齊方式。 (只針對type="image") |
alt | text | 定義影象輸入的替代文字。 (只針對type="image") |
autocompleteNew | on off | autocomplete 屬性規定 <input> 元素輸入欄位是否應該啟用自動完成功能。 |
autofocusNew | autofocus | 屬性規定當頁面載入時 <input> 元素應該自動獲得焦點。 |
checked | checked | checked 屬性規定在頁面載入時應該被預先選定的 <input> 元素。 (只針對 type="checkbox" 或者 type="radio") |
disabled | disabled | disabled 屬性規定應該禁用的 <input> 元素。 |
formNew | form_id | form 屬性規定 <input> 元素所屬的一個或多個表單。 |
formactionNew | URL | 屬性規定當表單提交時處理輸入控制元件的檔案的 URL。(只針對 type="submit" 和 type="image") |
formenctypeNew | application/x-www-form-urlencoded multipart/form-data text/plain | 屬性規定當表單資料提交到伺服器時如何編碼(只適合 type="submit" 和 type="image")。 |
formmethodNew | get post | 定義傳送表單資料到 action URL 的 HTTP 方法。 (只適合 type="submit" 和 type="image") |
formnovalidateNew | formnovalidate | formnovalidate 屬性覆蓋 <form> 元素的 novalidate 屬性。 |
formtargetNew | _blank _self _parent _top framename | 規定表示提交表單後在哪裡顯示接收到響應的名稱或關鍵詞。(只適合 type="submit" 和 type="image") |
heightNew | pixels | 規定 <input>元素的高度。(只針對type="image") |
listNew | datalist_id | 屬性引用 <datalist> 元素,其中包含 <input> 元素的預定義選項。 |
maxNew | number date | 屬性規定 <input> 元素的最大值。 |
maxlength | number | 屬性規定 <input> 元素中允許的最大字元數。 |
minNew | number date | 屬性規定 <input>元素的最小值。 |
multipleNew | multiple | 屬性規定允許使用者輸入到 <input> 元素的多個值。 |
name | text | name 屬性規定 <input> 元素的名稱。 |
patternNew | regexp | pattern 屬性規定用於驗證 <input> 元素的值的正則表示式。 |
placeholderNew | text | placeholder 屬性規定可描述輸入 <input> 欄位預期值的簡短的提示資訊 。 |
readonly | readonly | readonly 屬性規定輸入欄位是隻讀的。 |
requiredNew | required | 屬性規定必需在提交表單之前填寫輸入欄位。 |
size | number | size 屬性規定以字元數計的 <input> 元素的可見寬度。 |
src | URL | src 屬性規定顯示為提交按鈕的影象的 URL。 (只針對 type="image") |
stepNew | number | step 屬性規定 <input> 元素的合法數字間隔。 |
type | button checkbox color date datetime datetime-local file hidden image month number password radio range reset search submit tel text time url week |
type 屬性規定要顯示的 <input> 元素的型別。 |
value | text | 指定 <input> 元素 value 的值。 |
widthNew | pixels | width 屬性規定 <input> 元素的寬度。 (只針對type="image") |
全域性屬性
<input> 標籤支援全域性屬性,檢視完整屬性表 HTML全域性屬性。
事件屬性
<input> 標籤支援所有 HTML事件屬性。