HTML <input> 標籤
實例
一個簡單的HTML 表單,包含兩個文本輸入框和一個提交按鈕:
<form
action="demo_form.asp">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="提交">
</form>
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="提交">
</form>
嘗試一下»
(本頁底部可以查看更多實例)
瀏覽器支持
目前大多數瀏覽器支持<input>標籤。
標籤定義及使用說明
<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") |
autocomplete New | on off | autocomplete 屬性規定<input> 元素輸入字段是否應該啟用自動完成功能。 |
autofocus New | autofocus | 屬性規定當頁面加載時<input> 元素應該自動獲得焦點。 |
checked | checked | checked 屬性規定在頁面加載時應該被預先選定的<input> 元素。 (只針對type="checkbox" 或者type="radio") |
disabled | disabled | disabled 屬性規定應該禁用的<input> 元素。 |
form New | form_id | form 屬性規定<input> 元素所屬的一個或多個表單。 |
formaction New | URL | 屬性規定當表單提交時處理輸入控件的文件的URL。 (只針對type="submit" 和type="image") |
formenctype New | application/x-www-form-urlencoded multipart/form-data text/plain | 屬性規定當表單數據提交到服務器時如何編碼(只適合type="submit" 和type="image")。 |
formmethod New | get post | 定義發送表單數據到action URL 的HTTP 方法。 (只適合type="submit" 和type="image") |
formnovalidate New | formnovalidate | formnovalidate 屬性覆蓋<form> 元素的novalidate 屬性。 |
formtarget New | _blank _self _parent _top framename | 規定表示提交表單後在哪裡顯示接收到響應的名稱或關鍵詞。 (只適合type="submit" 和type="image") |
height New | pixels | 規定<input>元素的高度。 (只針對type="image") |
list New | datalist_id | 屬性引用<datalist> 元素,其中包含<input> 元素的預定義選項。 |
max New | number date | 屬性規定<input> 元素的最大值。 |
maxlength | number | 屬性規定<input> 元素中允許的最大字符數。 |
min New | number date | 屬性規定<input>元素的最小值。 |
multiple New | multiple | 屬性規定允許用戶輸入到<input> 元素的多個值。 |
name | text | name 屬性規定<input> 元素的名稱。 |
pattern New | regexp | pattern 屬性規定用於驗證<input> 元素的值的正則表達式。 |
placeholder New | text | placeholder 屬性規定可描述輸入<input> 字段預期值的簡短的提示信息。 |
readonly | readonly | readonly 屬性規定輸入字段是只讀的。 |
required New | required | 屬性規定必需在提交表單之前填寫輸入字段。 |
size | number | size 屬性規定以字符數計的<input> 元素的可見寬度。 |
src | URL | src 屬性規定顯示為提交按鈕的圖像的URL。 (只針對type="image") |
step New | 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 的值。 |
width New | pixels | width 屬性規定<input> 元素的寬度。 (只針對type="image") |
全局屬性
<input>標籤支持全局屬性,查看完整屬性表HTML全局屬性 。
事件屬性
<input>標籤支持所有HTML事件屬性 。