HTML5新Form表單元素和屬性有哪些

這篇文章主要為大家展示了“HTML5新Form表單元素和屬性有哪些”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“HTML5新Form表單元素和屬性有哪些”這篇文章吧。

10多年的祿勸網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營(yíng)銷(xiāo)的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整祿勸建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)公司從事“祿勸網(wǎng)站設(shè)計(jì)”,“祿勸網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。

HTML5新表單元素

HTML 5 擁有若干涉及表單的元素和屬性。

datalist  元素 datalist 元素規(guī)定輸入域的選項(xiàng)列表。 列表是通過(guò) datalist  內(nèi)的 option  元素創(chuàng)建的。 如需把 datalist  綁定到輸入域,請(qǐng)用輸入域的 list 屬性引用 datalist  的 id。

實(shí)例 :

Webpage: <input type="url" list="url_list" name="link" />

<datalist id="url_list">

<option label="W3School" value="http://www.W3School.com.cn" />

<option label="Google" value="http://www.google.com" />

<option label="Microsoft" value="http://www.microsoft.com" />

</datalist>

復(fù)制代碼

提示:option  元素必須要設(shè)置 value  屬性。

keygen 元素

keygen  元素的作用是提供一種驗(yàn)證用戶的可靠方法。 keygen  元素是密鑰對(duì)生成器(key-pair generator)。當(dāng)提交表單時(shí),會(huì)生成兩個(gè)鍵,一個(gè)是私鑰,一個(gè)公鑰。 私鑰(private key )存儲(chǔ)于客戶端,公鑰(public key)則被發(fā)送到服務(wù)器。公鑰可用于之后驗(yàn)證用戶的客戶端證書(shū)(client certificate )。 目前,瀏覽器對(duì)此元素的糟糕的支持度不足以使其成為一種有用的安全標(biāo)準(zhǔn)。

實(shí)例 :

<form action="demo_form.asp" method="get">

Username: <input type="text" name="usr_name" />

Encryption: <keygen name="security" />

<input type="submit" />

</form>

復(fù)制代碼

output 元素

output  元素用于不同類(lèi)型的輸出,比如計(jì)算或腳本輸出。

實(shí)例 :

<output id="result" onforminput="resCalc()"></output>

復(fù)制代碼

HTML5新表單屬性

給大家介紹一下 <form>  和 <input> 元素的新屬性。

新的 form 屬性: autocomplete 、novalidate

新的 input  屬性: autocomplete ,autofocus ,form ,form overrides (formaction, formenctype,  formmethod, formnovalidate, formtarget) ,height  和 width ,list min, max , step ,multiple ,pattern (regexp) ,placeholder, required

autocomplete 屬性

autocomplete 屬性規(guī)定 form 或 input  域應(yīng)該擁有自動(dòng)完成功能。 注釋?zhuān)篴utocomplete 適用于 <form>  標(biāo)簽,以及以下類(lèi)型的 <input> 標(biāo)簽:text, search, url, telephone, email, password, datepickers, range  以及 color 。 當(dāng)用戶在自動(dòng)完成域中開(kāi)始輸入時(shí),瀏覽器應(yīng)該在該域中顯示填寫(xiě)的選項(xiàng)。

實(shí)例 :

<form action="demo_form.asp" method="get" autocomplete="on">

First name: <input type="text" name="fname" /><br />

Last name: <input type="text" name="lname" /><br />

E-mail: <input type="email" name="email" autocomplete="off" /><br />

<input type="submit" />

</form>

復(fù)制代碼

注釋?zhuān)涸谀承g覽器中,您可能需要啟用自動(dòng)完成功能,以使該屬性生效。

autofocus 屬性 autofocus 屬性規(guī)定在頁(yè)面加載時(shí),域自動(dòng)地獲得焦點(diǎn)。

注釋?zhuān)篴utofocus 屬性適用于所有 <input> 標(biāo)簽的類(lèi)型。

實(shí)例 :

User name: <input type="text" name="user_name"    autofocus="autofocus" />

復(fù)制代碼

form  屬性

form  屬性規(guī)定輸入域所屬的一個(gè)或多個(gè)表單。 注釋?zhuān)篺orm  屬性適用于所有 <input> 標(biāo)簽的類(lèi)型。 form  屬性必須引用所屬表單的 id。

實(shí)例 :

<form action="demo_form.asp" method="get" id="user_form">

First name:<input type="text" name="fname" />

<input type="submit" />

</form>

Last name: <input type="text" name="lname" form="user_form" />

復(fù)制代碼

注釋?zhuān)喝缧枰靡粋€(gè)以上的表單,請(qǐng)使用空格分隔的列表。

表單重寫(xiě)屬性

表單重寫(xiě)屬性(form override attributes)允許您重寫(xiě) form 元素的某些屬性設(shè)定。

表單重寫(xiě)屬性有:

formaction -  重寫(xiě)表單的 action  屬性

formenctype -  重寫(xiě)表單的 enctype  屬性

formmethod -  重寫(xiě)表單的 method  屬性

formnovalidate -  重寫(xiě)表單的 novalidate 屬性

formtarget -  重寫(xiě)表單的 target  屬性

注釋?zhuān)罕韱沃貙?xiě)屬性適用于以下類(lèi)型的 <input> 標(biāo)簽:submit  和 image 。

實(shí)例 :

<form action="demo_form.asp" method="get" id="user_form">

E-mail: <input type="email" name="userid" /><br />

<input type="submit" value="Submit" />

<br />

<input type="submit" formaction="demo_admin.asp" value="Submit as admin" />

<br />

<input type="submit" formnovalidate="true" value="Submit without validation" />

<br />

</form>

復(fù)制代碼

注釋?zhuān)哼@些屬性對(duì)于創(chuàng)建不同的提交按鈕很有幫助。

height  和 width  屬性

height  和 width  屬性規(guī)定用于 image  類(lèi)型的 input  標(biāo)簽的圖像高度和寬度。

注釋?zhuān)篽eight  和 width  屬性只適用于 image  類(lèi)型的 <input> 標(biāo)簽。

實(shí)例 :

<input type="image" src="img_submit.gif" width="99" height="99" />

復(fù)制代碼

list  屬性

list  屬性規(guī)定輸入域的 datalist。datalist 是輸入域的選項(xiàng)列表。 注釋?zhuān)簂ist  屬性適用于以下類(lèi)型的 <input> 標(biāo)簽:text, search, url, telephone, email, date pickers, number, range  以及 color 。

實(shí)例 :

Webpage: <input type="url" list="url_list" name="link" />

<datalist id="url_list">

<option label="W3Schools" value="http://www.w3school.com.cn" />

<option label="Google" value="http://www.google.com" />

<option label="Microsoft" value="http://www.microsoft.com" />

</datalist>

復(fù)制代碼

min、max 和 step  屬性

min、max 和 step  屬性用于為包含數(shù)字或日期的 input  類(lèi)型規(guī)定限定(約束)。 max 屬性規(guī)定輸入域所允許的最大值。 min 屬性規(guī)定輸入域所允許的最小值。 step  屬性為輸入域規(guī)定合法的數(shù)字間隔(如果 step="3" ,則合法的數(shù)是 -3,0,3,6  等)。 注釋?zhuān)簃in、max 和 step  屬性適用于以下類(lèi)型的 <input> 標(biāo)簽:date pickers、number 以及 range。

下面的例子顯示一個(gè)數(shù)字域,該域接受介于 0  到 10 之間的值,且步進(jìn)為 3(即合法的值為 0、3、6  和 9)。

實(shí)例 :

Points: <input type="number" name="points" min="0" max="10" step="3" />

復(fù)制代碼

multiple 屬性

multiple 屬性規(guī)定輸入域中可選擇多個(gè)值。 注釋?zhuān)簃ultiple 屬性適用于以下類(lèi)型的 <input> 標(biāo)簽:email 和 file。

實(shí)例 :

Select images: <input type="file" name="img" multiple="multiple" />

復(fù)制代碼

novalidate  屬性

novalidate  屬性規(guī)定在提交表單時(shí)不應(yīng)該驗(yàn)證 form 或 input  域。 注釋?zhuān)簄ovalidate  屬性適用于 <form>  以及以下類(lèi)型的 <input> 標(biāo)簽:text, search, url, telephone, email, password, date pickers, range  以及 color。

實(shí)例 :

<form action="demo_form.asp" method="get" novalidate="true">

E-mail: <input type="email" name="user_email" />

<input type="submit" />

</form>

復(fù)制代碼

pattern 屬性

pattern 屬性規(guī)定用于驗(yàn)證 input  域的模式(pattern )。 模式(pattern )  是正則表達(dá)式。您可以在我們的  JavaScript  教程中學(xué)習(xí)到有關(guān)正則表達(dá)式的內(nèi)容。 注釋?zhuān)簆attern 屬性適用于以下類(lèi)型的 <input> 標(biāo)簽:text, search, url, telephone, email  以及 password 。 下面的例子顯示了一個(gè)只能包含三個(gè)字母的文本域(不含數(shù)字及特殊字符)。

實(shí)例 :

Country code: <input type="text" name="country_code"

pattern="[A-z]{3}" title="Three letter country code" />

復(fù)制代碼

placeholder 屬性

placeholder 屬性提供一種提示(hint ),描述輸入域所期待的值。 注釋?zhuān)簆laceholder 屬性適用于以下類(lèi)型的 <input> 標(biāo)簽:text, search, url, telephone, email 以及 password 。 提示(hint )會(huì)在輸入域?yàn)榭諘r(shí)顯示出現(xiàn),會(huì)在輸入域獲得焦點(diǎn)時(shí)消失。

實(shí)例 :

<input type="search" name="user_search"   placeholder="Search W3School" />

復(fù)制代碼

required  屬性

required  屬性規(guī)定必須在提交之前填寫(xiě)輸入域(不能為空)。 注釋?zhuān)簉equired  屬性適用于以下類(lèi)型的 <input> 標(biāo)簽:text, search, url, telephone, email, password, date pickers, number, checkbox, radio  以及 file 。

實(shí)例 :

Name: <input type="text" name="usr_name" required="required" />

以上是“HTML5新Form表單元素和屬性有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

本文標(biāo)題:HTML5新Form表單元素和屬性有哪些
標(biāo)題路徑:http://bm7419.com/article18/ijphgp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、品牌網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、網(wǎng)站收錄品牌網(wǎng)站設(shè)計(jì)、全網(wǎng)營(yíng)銷(xiāo)推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

營(yíng)銷(xiāo)型網(wǎng)站建設(shè)