<輸入>


HTML <input> 標籤

#實例

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
</head>
<body>

<form action="demo-form.php">
First name: <input type="text" name="FirstName" value="Mickey"><br>
Last name: <input type="text" name="LastName" value="Mouse"><br>
<input type="submit" value="提交">
</form>

<p>点击"提交"按钮,表单数据将被发送到服务器上的“demo-form.php”。</p>

</body>
</html>

執行實例»

點擊"運行實例" 按鈕查看線上實例


瀏覽器支援

1000.png

目前大多數瀏覽器支援 <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新標籤。

##屬性引用<datalist> 元素,其中包含<input> 元素的預先定義選項。 max屬性規定 <input> 元素的最大值。 maxlength#屬性規定 <input> 元素中允許的最大字元數。 min屬性規定 <input>元素的最小值。 multiplemultiple屬性規定允許使用者輸入到 <input> 元素的多個值。 name#name 屬性規定 <input> 元素的名稱。 patternpattern 屬性規定用於驗證<input> 元素的值的正規表示式。 placeholderplaceholder 屬性規定可描述輸入<input>字段預期值的簡短的提示訊息 。 readonlyreadonlyreadonly 屬性規定輸入欄位是唯讀的。 requiredrequired屬性規定必須在提交表單之前填入輸入欄位。 sizesize 屬性規定以字元數計的  <input> 元素的可見寬度。 src#src 屬性規定顯示為提交按鈕的圖片的 URL。 (只針對 type="image")steptypecheckboxvaluetextwidthNewpixels
屬性描述
#acceptaudio/* video/* image/*MIME_type規定透過檔案上傳來提交的檔案的類型。 (只針對type="file")
alignleft right top middle bottomHTML5已被廢棄,不贊成使用。規定影像輸入的對齊方式。 (只針對type="image")
alt#text定義影像輸入的替代文本。 (只針對type="image")
autocompleteNewon offautocomplete 屬性規定 <input> 元素輸入欄位是否應該啟用自動完成功能。
autofocusNewautofocus屬性規定當頁面載入時 <input>  元素應該自動獲得焦點。
checkedcheckedchecked 屬性規定在頁面載入時應該被預先選定的  <input> 元素。 (只針對type="checkbox" 或type="radio")
disableddisableddisabled 屬性規定應該停用的<input> ; 元素。
formNewform_idform 屬性規定<input> 元素所屬的一個或多個表單。
formactionNewURL屬性規定當表單提交時處理輸入控制項的文件的URL。 (只針對 type="submit" 和 type="image")
formenctypeNewapplication/x-www-form-urlencoded multipart/form-data text/plain屬性規定表單資料提交到伺服器時如何編碼(只適合 type="submit" 和 type="image")。
formmethodNewget post定義傳送表單資料到 action URL 的 HTTP 方法。 (只適合type="submit" 和type="image")
formnovalidateNewformnovalidateformnovalidate 屬性覆蓋<form> 元素的novalidate 屬性。
formtargetNew_blank _self _parent _topframename規定表示提交表單後在哪裡顯示接收到回應的名稱或關鍵字。 (只適合type="submit" 和type="image")
heightNewpixels規定 <input>元素的高度。(只針對type="image")
listNew#datalist_id
Newnumber date
number
Newnumber date
New
text
New#regexp
Newtext
New
number
URL
New#number##step 屬性規定< input> 元素的合法數字間隔。
buttoncolor
date
datetime
datetime-local
email
file
hidden
image
month
number
password
radio
range
reset
search
submit
tel
text
time
url
week

type 屬性規定要顯示的 <input> 元素的類型。
#指定 <input> 元素 value 的值。
width 屬性規定  <input> 元素的寬度。 (只針對type="image")

全域屬性

<input> 標籤支援全域屬性,檢視完整屬性表HTML全域屬性。

事件屬性

<input> 標籤支援所有 HTML事件屬性。

#