The input box in the DATALIST:HTML5 automatically prompts the treasure device

Source: Internet
Author: User
Tags ticket

The role of DataList is to enter the input box in your input information, according to the letter you hit, automatically display a hint of the following list, very much like Baidu or Google's search box automatic hints, in the air Ticket Train ticket Search page also has this effect. It is a very useful addition to the HTML5 element.

DataList's performance is much like a drop- Select down list, but it's just a hint and doesn't restrict what the user enters in the input box. HTML5 DataList syntax is almost exactly the same as the syntax of a drop- select down list, very simple!

<labelFor="Country_name"> Countries:</label><inputId="Country_name"Name="Country_name"Type=The text"List="Country"/><datalistId="Country"><optionValue="Afghanistan Afghanistan"><optionValue="Albania Albanian"><optionValue="Algeria Algeria ">  <option value< Span class= "token punctuation" >= "Andorra Andorra " Span class= "token punctuation" >>  <option value< Span class= "token punctuation" >= "Angola Angola " > </datalist>         

It is important to note that the value of the input box's list property is datalist the ID, so that datalist it can be associated with the input box, which was mentioned earlier when the range type was introduced. datalistdoes not display itself, it is displayed automatically only when it needs to mate with input inputs.

Let's look at a practical example, in the following input box, enter a few letters, DataList will prompt you to include these characters in the English country name.

Country name (English)

If your browser is too old to see the effect above, this image below will allow you to take a look at the eye addiction.

This example is in English, but Chinese is actually the same. You might as well try it out automatically. Very simple, before this effect basically can only use to speak JavaScript implementation, need you have quite JavaScript basic skills, and now, thanks to HTML5, only need pure HTML can achieve such magical effect.

DataList and Javasript also have some short boards, such as when the amount of data is very large, such as thousands of information, so that the amount of data should not be all written to the page, the use of JavaScript dynamic loading will improve efficiency. But for ordinary applications, the DataList is fully sufficient. What do you think?

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.