HTML新的表單屬性
HTML新的表單屬性
HTML5 的 <form> 和 <input>標(biāo)簽添加了幾個(gè)新屬性.
<form>新屬性:
autocomplete
novalidate
<input>新屬性:
autocomplete
autofocus
form
formaction
formenctype
formmethod
formnovalidate
formtarget
height and width
list
min and max
multiple
pattern (regexp)
placeholder
required
step
<form> / <input> autocomplete 屬性
autocomplete 屬性規(guī)定 form 或 input 域應(yīng)該擁有自動(dòng)完成功能。
當(dāng)用戶在自動(dòng)完成域中開始輸入時(shí),瀏覽器應(yīng)該在該域中顯示填寫的選項(xiàng)。
提示:?autocomplete 屬性有可能在 form元素中是開啟的,而在input元素中是關(guān)閉的。
注意:?autocomplete 適用于 <form> 標(biāo)簽,以及以下類型的 <input> 標(biāo)簽:text, search, url, telephone, email, password, datepickers, range 以及 color。
<form> novalidate 屬性
novalidate 屬性的一個(gè)boolean 屬性.
novalidate 屬性規(guī)定在提交表單時(shí)不應(yīng)該驗(yàn)證 form 或 input 域。
<input> autofocus 屬性
autofocus 屬性是一個(gè) boolean 屬性.
autofocus 屬性規(guī)定在頁面加載時(shí),域自動(dòng)地獲得焦點(diǎn)。
<input> form 屬性
form 屬性規(guī)定輸入域所屬的一個(gè)或多個(gè)表單。
提示:如需引用一個(gè)以上的表單,請(qǐng)使用空格分隔的列表。
<input> formaction 屬性
The formaction 屬性用于描述表單提交的URL地址.
The formaction 屬性會(huì)覆蓋<form> 元素中的action屬性.
注意:?The formaction 屬性用于 type="submit" 和 type="image".
<input> formenctype 屬性
formenctype 屬性描述了表單提交到服務(wù)器的數(shù)據(jù)編碼 (只對(duì)form表單中 method="post" 表單)
formenctype 屬性覆蓋 form 元素的 enctype 屬性。
主要:?該屬性與 type="submit" 和 type="image" 配合使用。
<input> formmethod 屬性
formmethod 屬性定義了表單提交的方式。
formmethod 屬性覆蓋了 <form> 元素的的method 屬性。
注意:?該屬性可以與 type="submit" 和 type="image" 配合使用。
<input> formnovalidate 屬性
novalidate 屬性是一個(gè) boolean 屬性.
novalidate屬性描述了 <input> 元素在表單提交時(shí)無需被驗(yàn)證。
formnovalidate 屬性會(huì)覆蓋 <form> 元素的novalidate屬性.
注意:?formnovalidate 屬性與type="submit一起使用
<input> formtarget 屬性
formtarget 屬性指定一個(gè)名稱或一個(gè)關(guān)鍵字來指明表單提交數(shù)據(jù)接收后的展示。
The formtarget 屬性覆蓋 <form>元素的target屬性.
注意:?formtarget 屬性與type="submit" 和 type="image"配合使用.
<input> height 和 width 屬性
height 和 width 屬性規(guī)定用于 image 類型的 <input> 標(biāo)簽的圖像高度和寬度。
注意:?height 和 width 屬性只適用于 image 類型的<input> 標(biāo)簽。
提示:圖像通常會(huì)同時(shí)指定高度和寬度屬性。如果圖像設(shè)置高度和寬度,圖像所需的空間 在加載頁時(shí)會(huì)被保留。如果沒有這些屬性, 瀏覽器不知道圖像的大小,并不能預(yù)留 適當(dāng)?shù)目臻g。圖片在加載過程中會(huì)使頁面布局效果改變 (盡管圖片已加載)。
<input> list 屬性
list 屬性規(guī)定輸入域的 datalist。datalist 是輸入域的選項(xiàng)列表。
<input> min 和 max 屬性
min、max 和 step 屬性用于為包含數(shù)字或日期的 input 類型規(guī)定限定(約束)。
注意:?min、max 和 step 屬性適用于以下類型的 <input> 標(biāo)簽:date pickers、number 以及 range。
<input> multiple 屬性
multiple 屬性是一個(gè) boolean 屬性.
multiple 屬性規(guī)定<input> 元素中可選擇多個(gè)值。
注意:?multiple 屬性適用于以下類型的 <input> 標(biāo)簽:email 和 file。: email, and file.
<input> pattern 屬性
pattern 屬性描述了一個(gè)正則表達(dá)式用于驗(yàn)證 <input> 元素的值。
注意:pattern 屬性適用于以下類型的 <input> 標(biāo)簽: text, search, url, tel, email, 和 password.
提示:?是用來全局?title?屬性描述了模式.
<input> placeholder 屬性
placeholder 屬性提供一種提示(hint),描述輸入域所期待的值。
簡短的提示在用戶輸入值前會(huì)顯示在輸入域上。
注意:?placeholder 屬性適用于以下類型的 <input> 標(biāo)簽:text, search, url, telephone, email 以及 password。
<input> required 屬性
required 屬性是一個(gè) boolean 屬性.
required 屬性規(guī)定必須在提交之前填寫輸入域(不能為空)。
注意:required 屬性適用于以下類型的 <input> 標(biāo)簽:text, search, url, telephone, email, password, date pickers, number, checkbox, radio 以及 file。
<input> step 屬性
step 屬性為輸入域規(guī)定合法的數(shù)字間隔。
如果 step="3",則合法的數(shù)是 -3,0,3,6 等
提示:?step 屬性可以與 max 和 min 屬性創(chuàng)建一個(gè)區(qū)域值.
注意:?step 屬性與以下type類型一起使用: number, range, date, datetime, datetime-local, month, time 和 week.
在下面的案例中,我們對(duì)一些常用的屬性做了解釋,大家直接看代碼和代碼旁邊的注釋,然后對(duì)照瀏覽器的運(yùn)行結(jié)果就理解其意義了
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title></title> </head> <body> <!-- placeholder:用于在文本框未輸入時(shí)提示作用 autofocus:用于控件自動(dòng)獲取焦點(diǎn) --> <input type="search" name="key" value="" results="s" placeholder="君樂寶" autofocus="true"> <input type="button" name="" value="搜索"> <!-- novalidate:在控件中加入了required、emial、url等驗(yàn)證后,如果想讓這些驗(yàn)證失效,可以在表單中將novalidate設(shè)置為tyue --> <form action="upload.php" method="post" accept-charset="utf-8" id="form1" novalidate="true"> <br/><br/> <!-- required:必填 autocomplete:在網(wǎng)頁的文本框中輸入部分內(nèi)容或者雙節(jié)時(shí),經(jīng)常會(huì)看到在下面顯示輸入過的內(nèi)容, 這就是html5的新特性:自動(dòng)完成,如果不想使用此功能,將其設(shè)置為off即可 --> <input type="text" name="UserName" value="" required autocomplete="off"> <br/><br/> <!-- multiple:在選擇文件時(shí),默認(rèn)只能單選,加上這個(gè)屬性后,則可以使用鼠標(biāo)選中多個(gè)文件進(jìn)行上傳 --> 選擇文件 <input type="file" name="upload" value="" multiple="multiple"> <br/><br/> <!-- list:這個(gè)屬性要和datalist元素一起使用,指定此文本框的可選擇項(xiàng),另外其相較于select的優(yōu)點(diǎn)在于還可以輸入 --> 區(qū)號(hào): <input type="text" name="age" value="" list="list1"> <br/><br/> <datalist id="list1"> <option value="0312">保定</option> <option value="0311">石家莊</option> <option value="010">北京</option> <option value="0313">唐山</option> </datalist> <br/><br/> <!-- formaction:可以更改點(diǎn)擊此按鈕式提交到服務(wù)器的處理程序 formmethod:可以更改向服務(wù)器提交數(shù)據(jù)的方式 --> <input type="submit" name="subsave" value="提交"><br/><br/> <input type="submit" name="subresset" value="更改" formaction="1.php" formmethod="get"> </form> </body> </html>