html <input> 標(biāo)簽設(shè)置了用戶可以在其中輸入數(shù)據(jù)的輸入字段
<input> 元素在 <form> 元素中使用,用來聲明允許用戶輸入數(shù)據(jù)的 input 控件
輸入字段可通過多種方式改變,取決于 type 屬性
<input> 元素是空的,它只包含標(biāo)簽屬性
可以使用 <label> 元素來定義 <input> 元素的標(biāo)注
屬性
|
屬性
|
值
|
描述
|
|
accept
|
audio/ * video/ * image/ * MIME_type
|
設(shè)置通過文件上傳來提交的文件的類型,只針對type="file"
|
|
align
|
left right top middle bottom
|
html5 已廢棄,不贊成使用 設(shè)置圖像輸入的對齊方式,只針對 type="image"
|
|
alt
|
text
|
定義圖像輸入的替代文本,只針對type="image"
|
|
autocomplete
|
on off
|
autocomplete 屬性設(shè)置 <input> 元素輸入字段是否應(yīng)該啟用自動完成功能
|
|
autofocus
|
autofocus
|
屬性設(shè)置當(dāng)頁面加載時(shí) <input> 元素應(yīng)該自動獲得焦點(diǎn)
|
|
checked
|
checked
|
checked 屬性設(shè)置在頁面加載時(shí)應(yīng)該被預(yù)先選定的 <input> 元素。 (只針對 type="checkBox" 或者 type="radio")
|
|
disabled
|
disabled
|
disabled 屬性設(shè)置應(yīng)該禁用的 <input> 元素
|
|
form
|
form_id
|
form 屬性設(shè)置 <input> 元素所屬的一個(gè)或多個(gè)表單
|
|
formaction
|
URL
|
屬性設(shè)置當(dāng)表單提交時(shí)處理輸入控件的文件的 URL。(只針對 type="submit" 和 type="image")
|
|
formenctype
|
application/x-www-form-urlencoded multipart/form-data text/plain
|
屬性設(shè)置當(dāng)表單數(shù)據(jù)提交到服務(wù)器時(shí)如何編碼(只適合 type="submit" 和 type="image")
|
|
formmethod
|
get post
|
定義發(fā)送表單數(shù)據(jù)到 action URL 的 HTTP 方法。 (只適合 type="submit" 和 type="image")
|
|
formnovalidate
|
formnovalidate
|
formnovalidate 屬性覆蓋 <form> 元素的 novalidate 屬性
|
|
formtarget
|
_blank _self _parent _top framename
|
設(shè)置表示提交表單后在哪里顯示接收到響應(yīng)的名稱或關(guān)鍵詞。(只適合 type="submit" 和 type="image")
|
|
height
|
pixels
|
設(shè)置 <input>元素的高度。(只針對type="image")
|
|
list
|
datalist_id
|
屬性引用 <datalist> 元素,其中包含 <input> 元素的預(yù)定義選項(xiàng)
|
|
max
|
number
date
|
屬性設(shè)置 <input> 元素的最大值
|
|
maxlength
|
number
|
屬性設(shè)置 <input> 元素中允許的最大字符數(shù)
|
|
min
|
number
date
|
屬性設(shè)置 <input>元素的最小值
|
|
multiple
|
multiple
|
屬性設(shè)置允許用戶輸入到 <input> 元素的多個(gè)值
|
|
name
|
text
|
name 屬性設(shè)置 <input> 元素的名稱
|
|
pattern
|
regexp
|
pattern 屬性設(shè)置用于驗(yàn)證 <input> 元素的值的正則表達(dá)式
|
|
placeholder
|
text
|
placeholder 屬性設(shè)置可描述輸入 <input> 字段預(yù)期值的簡短的提示信息
|
|
readonly
|
readonly
|
readonly 屬性設(shè)置輸入字段是只讀的
|
|
required
|
required
|
屬性設(shè)置必需在提交表單之前填寫輸入字段
|
|
size
|
number
|
size 屬性設(shè)置以字符數(shù)計(jì)的 <input> 元素的可見寬度
|
|
src
|
URL
|
src 屬性設(shè)置顯示為提交按鈕的圖像的 URL 只針對 type="image"
|
|
step
|
number
|
step 屬性設(shè)置 <input> 元素的合法數(shù)字間隔
|
|
type
|
button checkBox color date datetime datetime-local email file hidden image month number password radio range reset search submit tel text time url week
|
type 屬性設(shè)置要顯示的 <input> 元素的類型
|
|
value
|
text
|
指定 <input> 元素 value 的值
|
|
width
|
pixels
|
width 屬性設(shè)置 <input> 元素的寬度 只針對 type="image"
|
范例
一個(gè)簡單的 HTML 表單,包含兩個(gè)文本輸入框和一個(gè)提交按鈕
<form action="/dy/html/getpost">
First name: <input type="text" name="fname"><br>
Last name:
<input type="text" name="lname"><br>
<input type="submit" value="提交">
</form>
HTML 4.01 與 HTML5之間的差異
HTML 4.01 中,"align" 屬性已經(jīng)不再使用
HTML5 中不支持該屬性,可以使用 css 來定義 <input> 元素的對齊方式
HTML5 中,<input> 添加了幾個(gè)屬性,并且添加了對應(yīng)的值
HTML 與 XHTML 之間的差異
HTML 中,<input> 標(biāo)簽沒有結(jié)束標(biāo)簽
XHTML 中,<input> 標(biāo)簽必須被正確地關(guān)閉
全局屬性
<input> 標(biāo)簽支持全局屬性,查看完整屬性表 HTML全局屬性
事件屬性
<input> 標(biāo)簽支持所有 HTML事件屬性
|