jquery implementation HTML5 Placeholder effect example _jquery

Source: Internet
Author: User

You must know HTML5 's new placeholder attribute, right? It doesn't matter if you don't know. The input box has the default text is, often need such an effect, click let the default text disappear, lose focus and let the default text display.

Share a piece of jquery code today, simulating placeholder effects.

JavaScript code:

Copy Code code as follows:

Function placeholder (event) {
var self = $ (this), Selfdatavalue = Self.attr ("Data-value"), Selfvalue = Self.val ();
if (Selfdatavalue) {
Event.type = = "click"? (Selfvalue = = Selfdatavalue && (Self.val (""). CSS ("Color", "#333")): (Event.type = = "Blur" && (Selfvalue = = "" && (Self.val (selfdatavalue). CSS ("Color", "#A9A9A9"))
}else{
return false;
}
}
$ (". Pinputtext"). On ("click Blur", placeholder);

HTML code:

Copy Code code as follows:

<input type= "text" value= "Search Here" class= "Pinputtext"/>

Some people may ask, since HTML5 provide such a function, there are JS write why?

This is not nonsense, of course, the compatibility of the problem, ie if the HTML5 compatible with a better word, who would like to use JS to achieve this thing ah.

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.