"JQuery" makes IE's input box complete placeholder's mission

Source: Internet
Author: User

If you add the placeholder= "xx" attribute to the input box, for example:

<input type= "text" placeholder= "Please enter keywords"/>

You can implement the function of replacing text in the input boxes of advanced browsers such as Google Chrome, which is to get the dialog box as shown:


But this property is not compatible in WIN7 default browser IE8, let's not say IE6. In other words, IE does not support placeholder this tag.

If you don't believe it, you can pull this piece of code into the IE8 and try it, you're just getting an empty dialog box.

In IE, in order to achieve this to use the component loses focus blur and get focus inside to do, in detail can refer to the "JavaScript" Component focus and page anchor points between the value "(Click Open link)

In fact, you can not use jquery at all, this is to review the "jquery" Control node, only in the foreground through the Get method to complete the parameter transfer (click to open the link)

The idea is simple, at first this text box defaults to #cccccc gray font, the value is "Please enter a keyword", when the focus, set its color to #000000 black, the value is empty, once it loses focus, if the value is empty, immediately restore it to the default #cccccc gray font, the value is " Please enter the keyword "

The code is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">Note here is that it is to add a Boolean value of Isthisnull to determine whether it is empty, in order to determine whether the user should enter "Please enter a keyword",

Can not think of the text box inside the "Please enter a keyword" is empty, if the user input "Please enter keywords"?

You should not use jquery or JavaScript to determine whether a color or style value is "#cccccc" or "Color: #cccccc" Because the color is taken by the $ (this). CSS ("color"). In the browser output is not the same as the result, and take the style, IE will think that this is an object, rather than a string

Set up a isthisnull, or you can prepare for further forms validation later

Finally, the following effects are obtained in IE:



"JQuery" makes IE's input box complete placeholder's mission

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.