New features of HTML5 's form

Source: Internet
Author: User

New input controls for form:

Name Description Legend
Email e-mail text box, showing no difference from normal
Tel Phone number ,pc side will not have obvious changes, but the mobile side will automatically switch the keyboard, input error does not prevent the default submission
Url Web page URL
Search search engine, chrome under the input text, will be more than a closed x
Range Value selectors in a specific range, Min, max, step (steps)
Number You can only include numbers in the input box, there is a keyboard listener, you cannot enter other characters.
Color Color Picker
Datetime Show full Date Direct use seems impossible.
Datetime-local Full date is displayed, no time zone included
Time Display time, without time zone
Date Display date, Time control
Week Show week
Month Show month

Form new forms features and functions  

    1. PLACEHOLDER: input box prompt information.

    2. AutoComplete: Whether to save user input values. The default is on, turn off the prompt to select off.

    3. Autofocus: Specifies that the form gets the input focus.

    4. List and DataList: Constructs a selection list for the input box.

    5. The list value is the ID of the DataList tag.

    6. Required: This entry is required and cannot be empty. (can be directly cracked)

    7. Pattern: Regular validation pattern= "\d{1,5}". (can be directly cracked)
    8. FormAction defines the submission address in the submit and overrides the form's action property.

Form form Validation

  1. Invalid event: Otext.addeventlistener ("invalid", fn1,false);

  2. Validity object, the following valid can be used to see if the validation passed.
  3. Block default validation: Ev.preventdefault ().
    1 <!DOCTYPE HTML>2 <HTML>3     <Head>4         <MetaCharSet= "UTF-8">5         <title></title>6     </Head>7     <Body>8          <formAction= "Http://www.baidu.com"Method= "POST"ID= "MyForm">9              <inputtype= "text"ID= "username"name= "username"Required= "Required"/>Ten              <inputtype= "Submit"value= "Submit"/> One          </form> A     </Body> - </HTML> - <Scripttype= "Text/javascript"> the window.onload= function(){ -         varOinput=document.getElementById ("username"); -         //If you do not add a listener function, username does not fill in, the browser will default block form submission, and give a hint: Please fill in this field.  -         //If there is an addition, the validation failure executes the function first, and the value of This.validity.valid is false.  +         //if Ev.preventdefault () is not added to the function, the browser will also give a hint: Please fill in this field. Adding means blocking the default prompt.  - Oinput.addeventlistener ("Invalid",function(EV) { + Console.log ( This. validity. valid); A //Ev.preventdefault (); at         },false); -     } - </Script>
  4. Formnovalidate attribute: Used in <input type= "Submit" value= "commit" formnovalidate= "Formnovalidate"/>, add this property, then turn off validation.
  5. Valuemissing: When the input value is empty.
  6. Typemismatch: The control value does not match the expected type.

  7. Patternmismatch: The input value does not satisfy the pattern regular.
  8. Toolong: Maximum limit exceeded maxlength.

  9. Rangeunderflow: The range minimum value validated.
  10. Rangeoverflow: The range maximum value verified

  11. Stepmismatch: Verifies that the current value of range conforms to the rules for Min, Max, and step.

  12. Setcustomvalidity (); Custom validation.

    1 <!DOCTYPE HTML>2 <HTML>3     <Head>4         <MetaCharSet= "UTF-8">5         <title></title>6     </Head>7     <Body>8         <formname= "MyForm"Action=""Method= "POST">9             <inputtype= "text"name=""ID= "MyNumber"value=""Required= "Required"/>Ten             <inputtype= "Submit"name=""ID=""value= "Submit" /> One         </form A </body> -  - </HTML> the <Scripttype= "Text/javascript"> - window.onload= function(){ -         varOnumber=document.getElementById ("MyNumber"); - onumber.setcustomvalidity ("Required fields, please enter! "); +     } - </Script>

New features of HTML5 's form

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.