Implementation Code for automatically displaying specified data without a value in the jQuery-based input box _ jquery

Source: Internet
Author: User
In your own webpage, you often need to specify the style input box, when the input box does not enter or only enter space and other invalid information, automatically display the specified text, to remind the user how to perform the operation, the following is the specific implementation method, for reference only. [Solution]

1. Preparations

(1) input box

The Code is as follows:




(2) CSS code

The Code is as follows:


Input. helpText {color: # aaa ;}


(3) Conversion Method

The Code is as follows:


Function switchText ()
{
If ($ (this). val () ==$ (this). attr ('title '))
$ (This). val (''). removeClass ('helptext ');
Else if ($. trim ($ (this). val () = '')
$ (This). addClass ('helptext'). val ($ (this). attr ('title '));
}


(4) specific implementation

The Code is as follows:


$ ('Input [type = text] [title! = ""] '). Each (function (){
If ($. trim ($ (this). val () = '') $ (this). val ($ (this). attr ('title '));
If ($ (this). val () ==$ (this). attr ('title') $ (this). addClass ('helptext ');
}). Focus (switchText). blur (switchText );

$ ('Form'). submit (function (){
$ (This). find ('input [type = text] [title! = ""] '). Each (function (){
If ($ (this). val () ==$ (this). attr ('title') $ (this). val ('');
});
});


2. References
Http://webservices.blog.gustavus.edu/2008/06/23/text-input-example-text-with-jquery/

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.