HTML5 ±íµ¥ÊôÐÔ
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
ä¯ÀÀÆ÷Ö§³Ö
Input type | IE | Firefox | Opera | Chrome | Safari |
---|---|---|---|---|---|
autocomplete | 8.0 | 3.5 | 9.5 | 3.0 | 4.0 |
autofocus | No | No | 10.0 | 3.0 | 4.0 |
form | No | No | 9.5 | No | No |
form overrides | No | No | 10.5 | No | No |
height and width | 8.0 | 3.5 | 9.5 | 3.0 | 4.0 |
list | No | No | 9.5 | No | No |
min, max and step | No | No | 9.5 | 3.0 | No |
multiple | No | 3.5 | No | 3.0 | 4.0 |
novalidate | No | No | No | No | No |
pattern | No | No | 9.5 | 3.0 | No |
placeholder | No | No | No | 3.0 | 3.0 |
required | No | No | 9.5 | 3.0 | No |
autocomplete ÊôÐÔ
autocomplete ÊôÐԹ涨 form »ò input ÓòÓ¦¸ÃÓµÓÐ×Ô¶¯Íê³É¹¦ÄÜ¡£
×¢ÊÍ£ºautocomplete ÊÊÓÃÓÚ <form> ±êÇ©£¬ÒÔ¼°ÒÔÏÂÀàÐ굀 <input> ±êÇ©£ºtext, search, url, telephone, email, password, datepickers, range ÒÔ¼° color¡£
µ±Óû§ÔÚ×Ô¶¯Íê³ÉÓòÖпªÊ¼ÊäÈëʱ£¬ä¯ÀÀÆ÷Ó¦¸ÃÔÚ¸ÃÓòÖÐÏÔʾÌîдµÄÑ¡Ï
ʵÀý
<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>
×¢ÊÍ£ºÔÚijЩä¯ÀÀÆ÷ÖУ¬Äú¿ÉÄÜÐèÒªÆôÓÃ×Ô¶¯Íê³É¹¦ÄÜ£¬ÒÔʹ¸ÃÊôÐÔÉúЧ¡£
autofocus ÊôÐÔ
autofocus ÊôÐԹ涨ÔÚÒ³Ãæ¼ÓÔØÊ±£¬Óò×Ô¶¯µØ»ñµÃ½¹µã¡£
×¢ÊÍ£ºautofocus ÊôÐÔÊÊÓÃÓÚËùÓÐ <input> ±êÇ©µÄÀàÐÍ¡£
ʵÀý
User name: <input type="text" name="user_name" autofocus="autofocus"
/>
form ÊôÐÔ
form ÊôÐԹ涨ÊäÈëÓòËùÊôµÄÒ»¸ö»ò¶à¸ö±íµ¥¡£
×¢ÊÍ£ºform ÊôÐÔÊÊÓÃÓÚËùÓÐ <input> ±êÇ©µÄÀàÐÍ¡£
form ÊôÐÔ±ØÐëÒýÓÃËùÊô±íµ¥µÄ id£º
ʵÀý
<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"
/>
×¢ÊÍ£ºÈçÐèÒýÓÃÒ»¸öÒÔÉÏµÄ±íµ¥£¬ÇëʹÓÿոñ·Ö¸ôµÄÁÐ±í¡£
±íµ¥ÖØÐ´ÊôÐÔ
±íµ¥ÖØÐ´ÊôÐÔ£¨form override attributes£©ÔÊÐíÄúÖØÐ´ form ÔªËØµÄijЩÊôÐÔÉ趨¡£
±íµ¥ÖØÐ´ÊôÐÔÓУº
- formaction - ÖØÐ´±íµ¥µÄ action ÊôÐÔ
- formenctype - ÖØÐ´±íµ¥µÄ enctype ÊôÐÔ
- formmethod - ÖØÐ´±íµ¥µÄ method ÊôÐÔ
- formnovalidate - ÖØÐ´±íµ¥µÄ novalidate ÊôÐÔ
- formtarget - ÖØÐ´±íµ¥µÄ target ÊôÐÔ
×¢ÊÍ£º±íµ¥ÖØÐ´ÊôÐÔÊÊÓÃÓÚÒÔÏÂÀàÐ굀 <input> ±êÇ©£ºsubmit ºÍ image¡£
ʵÀý
<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>
×¢ÊÍ£ºÕâЩÊôÐÔ¶ÔÓÚ´´½¨²»Í¬µÄÌá½»°´Å¥ºÜÓаïÖú¡£
height ºÍ width ÊôÐÔ
height ºÍ width ÊôÐԹ涨ÓÃÓÚ image ÀàÐ굀 input ±êÇ©µÄͼÏñ¸ß¶ÈºÍ¿í¶È¡£
×¢ÊÍ£ºheight ºÍ width ÊôÐÔÖ»ÊÊÓÃÓÚ image ÀàÐ굀 <input> ±êÇ©¡£
ʵÀý
<input type="image" src="img_submit.gif"width="99"
height="99"
/>
list ÊôÐÔ
list ÊôÐԹ涨ÊäÈëÓòµÄ datalist¡£datalist ÊÇÊäÈëÓòµÄÑ¡ÏîÁÐ±í¡£
×¢ÊÍ£ºlist ÊôÐÔÊÊÓÃÓÚÒÔÏÂÀàÐ굀 <input> ±êÇ©£ºtext, search, url, telephone, email, date pickers, number, range ÒÔ¼° color¡£
ʵÀý
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>
min¡¢max ºÍ step ÊôÐÔ
min¡¢max ºÍ step ÊôÐÔÓÃÓÚΪ°üº¬Êý×Ö»òÈÕÆÚµÄ input ÀàÐ͹涨ÏÞ¶¨£¨Ô¼Êø£©¡£
max ÊôÐԹ涨ÊäÈëÓòËùÔÊÐíµÄ×î´óÖµ¡£
min ÊôÐԹ涨ÊäÈëÓòËùÔÊÐíµÄ×îСֵ¡£
step ÊôÐÔΪÊäÈëÓò¹æ¶¨ºÏ·¨µÄÊý×Ö¼ä¸ô£¨Èç¹û step="3"£¬ÔòºÏ·¨µÄÊýÊÇ -3,0,3,6 µÈ£©¡£
×¢ÊÍ£ºmin¡¢max ºÍ step ÊôÐÔÊÊÓÃÓÚÒÔÏÂÀàÐ굀 <input> ±êÇ©£ºdate pickers¡¢number ÒÔ¼° range¡£
ÏÂÃæµÄÀý×ÓÏÔʾһ¸öÊý×ÖÓò£¬¸ÃÓò½ÓÊܽéÓÚ 0 µ½ 10 Ö®¼äµÄÖµ£¬ÇÒ²½½øÎª 3£¨¼´ºÏ·¨µÄֵΪ 0¡¢3¡¢6 ºÍ 9£©£º
ʵÀý
Points: <input type="number" name="points"min="0"
max="10"
step="3"
/>
multiple ÊôÐÔ
multiple ÊôÐԹ涨ÊäÈëÓòÖпÉÑ¡Ôñ¶à¸öÖµ¡£
×¢ÊÍ£ºmultiple ÊôÐÔÊÊÓÃÓÚÒÔÏÂÀàÐ굀 <input> ±êÇ©£ºemail ºÍ file¡£
ʵÀý
Select images: <input type="file" name="img" multiple="multiple"
/>
novalidate ÊôÐÔ
novalidate ÊôÐԹ涨ÔÚÌá½»±íµ¥Ê±²»Ó¦¸ÃÑéÖ¤ form »ò input Óò¡£
×¢ÊÍ£ºnovalidate ÊôÐÔÊÊÓÃÓÚ <form> ÒÔ¼°ÒÔÏÂÀàÐ굀 <input> ±êÇ©£ºtext, search, url, telephone, email, password, date pickers, range ÒÔ¼° color.
ʵÀý
<form action="demo_form.asp" method="get" novalidate="true"
>
E-mail: <input type="email" name="user_email" />
<input type="submit" />
</form>
pattern ÊôÐÔ
pattern ÊôÐԹ涨ÓÃÓÚÑéÖ¤ input ÓòµÄģʽ£¨pattern£©¡£
ģʽ£¨pattern£© ÊÇÕýÔò±í´ïʽ¡£Äú¿ÉÒÔÔÚÎÒÃÇµÄ JavaScript ½Ì³ÌÖÐѧϰµ½ÓйØÕýÔò±í´ïʽµÄÄÚÈÝ¡£
×¢ÊÍ£ºpattern ÊôÐÔÊÊÓÃÓÚÒÔÏÂÀàÐ굀 <input> ±êÇ©£ºtext, search, url, telephone, email ÒÔ¼° password¡£
ÏÂÃæµÄÀý×ÓÏÔʾÁËÒ»¸öÖ»Äܰüº¬Èý¸ö×ÖĸµÄÎı¾Óò£¨²»º¬Êý×Ö¼°ÌØÊâ×Ö·û£©£º
ʵÀý
Country code: <input type="text" name="country_code"
pattern="[A-z]{3}"
title="Three letter country code" />
placeholder ÊôÐÔ
placeholder ÊôÐÔÌṩһÖÖÌáʾ£¨hint£©£¬ÃèÊöÊäÈëÓòËùÆÚ´ýµÄÖµ¡£
×¢ÊÍ£ºplaceholder ÊôÐÔÊÊÓÃÓÚÒÔÏÂÀàÐ굀 <input> ±êÇ©£ºtext, search, url, telephone, email ÒÔ¼° password¡£
Ìáʾ£¨hint£©»áÔÚÊäÈëÓòΪ¿ÕʱÏÔʾ³öÏÖ£¬»áÔÚÊäÈëÓò»ñµÃ½¹µãʱÏûʧ£º
ʵÀý
<input type="search" name="user_search" placeholder="Search W3School"
/>
required ÊôÐÔ
required ÊôÐԹ涨±ØÐëÔÚÌύ֮ǰÌîдÊäÈëÓò£¨²»ÄÜΪ¿Õ£©¡£
×¢ÊÍ£ºrequired ÊôÐÔÊÊÓÃÓÚÒÔÏÂÀàÐ굀 <input> ±êÇ©£ºtext, search, url, telephone, email, password, date pickers, number, checkbox, radio ÒÔ¼° file¡£
ʵÀý
Name: <input type="text" name="usr_name" required="required"
/>