JQuery click the text box to clear the Content Code instance. jquery text box

Source: Internet
Author: User

JQuery click the text box to clear the Content Code instance. jquery text box

Click the text box in jQuery to clear the code example:
This topic describes the most simple and user-friendly way to delete prompt text when you click the text box.
The code example is as follows:

<! DOCTYPE html> 

The above code implements our requirements. The following describes the implementation process.
I. Code comments:
1. $ (document). ready (function () {}). When the document structure is fully loaded, the code in the execution function is executed.
2. $ ("# email"). focus (function () {}), register the focus event handler function for the text box.
3. var email_txt = $ (this). val () to obtain the value of the text box.
4. if (email_txt = this. defaultValue) {$ (this). val ("") ;}, if the value of the text box is the same as the default value, the text box is cleared.
5. $ ("# email"). blur (function () {}), register the blur event handler function for the text box.
6. var email_txt = $ (this). val () to obtain the value of the text box.
7. if (email_txt = "") {$ (this ). val (this. defaultValue) ;}, if the text box value is null, the text box value is restored to the default.
Ii. Related reading:
1. For details about the focus event, see the focus event section of jQuery.
2. For more information about the val () function, see the val () method section of jQuery.
3. For details about the defaultValue attribute, see the section "text. defaultValue attribute" in javascript.
4. For more information about blur events, see the section blur events in jQuery.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 14210.

For more information, see: http://www.softwhy.com/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.