JQuery implements HTML5 placeholder effect instance, html5placeholder

Source: Internet
Author: User

JQuery implements HTML5 placeholder effect instance, html5placeholder

Do you know the placeholder attribute added to HTML5? It doesn't matter if you don't know. The default text in the input box is. This effect is often required. Click to make the default text disappear, and the default text is displayed after the focus is lost.

Today I will share a piece of jQuery code to simulate the placeholder effect.

Javascript code:

Copy codeThe Code is 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(selfdatavalue0000.css ("color", "# A9A9A9 "))))
} Else {
Return false;
}
}
$ (". PInputText"). on ("click blur", placeHolder );

Html code:

Copy codeThe Code is as follows:
<Input type = "text" value = "search for" class = "pInputText"/>

Some may ask, since html5 provides such a function, why is there js writing?

This is not nonsense. Of course, it is about compatibility. If IE is better compatible with HTML5, who would like to use js to implement this.

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.