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/