Analysis: default prompt information in the input box of the input Form

Source: Internet
Author: User

I believe that you have seen the prompt information in the input boxes of the above two images, and some people should have done it themselves.

I have done the same thing before. I should write the prompt content in the input box. When the mouse gets the focus, the content is cleared. when the focus is lost, the system checks whether the content is empty, if this parameter is set to null, the prompt content is restored. Otherwise, the prompt content is not displayed. But is this practice reasonable? Let's perform the analysis one by one.

1. If the input content is exactly the same as the prompt content, how should we determine if the focus is lost?

2. If the input is in the form, after the form is submitted, the system prompts that the information will be submitted along with the form. Do you still need to judge at the backend that the submitted information is not the same as the prompt information before performing data operations?

3. If both 1 and 2 are triggered, do backend operations need to be performed?

Since this practice has so many shortcomings, how can it be better? In fact, the method is very simple. Write the prompt information in a module, such as div, and set the style of the div so that it can be moved to the input box. As for js, you only need to write one more sentence, when I click this div, it also triggers the get focus event in the input box.

The advantage of doing so is that it not only solves the problems of and, but also prompts content not limited to text. You can be an image or even flash, greatly enhancing user interaction.

Simple Section Page code:

<Input class = "search" type = "text" name = "search"> <div id = "searchtip" style = "position: relative; color: # ccc "> <div style =" position: absolute; top:-18px; left: 4px "> enter the information </div>

Appendix 1: I have integrated this function into my own plug-ins. For details, refer to jquery. HooRay, a commonly used jquery tool plug-in.

Appendix 2: Learn about the PLACEHOLDER attribute of html5. click here

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.