Introduction to autofocus attributes in HTML5

Source: Internet
Author: User

Comments: HTML5 brings us a lot of amazing things. Previous tasks that need to be completed using JavaScript and Flash, such as form verification, INPUT placeholders, client renaming and downloading files and audio/video, can be completed using basic HTML

A simple HTML5 function is to let the input focus automatically fall into an element when the page is loaded. This action is completed using the autofocus attribute.

HTML code is very simple:

The Code is as follows:
<! -- These all work! -->
<Input autofocus = "autofocus"/>
<Button autofocus = "autofocus"> Hi! </Button>
<Textarea autofocus = "autofocus"> </textarea>
When the autofocus attribute is available, all the INPUT, TEXTAREA, or BUTTON elements can be loaded on the page and selected. However, if you use a pure display element, such as the H1 tag, the autofocus attribute is not easy to use.

This attribute is useful in some cases. For example, on Google's homepage, people use it for 99% of their time. Therefore, once a page is loaded, the cursor must be positioned in the input box. In the past, JavaScript was required. Now, html can be completed without any need.


Related Article

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.