jQueryimplements the default value of the text box to sense mouse movements.This chapter introduces how to usejQueryto implement the default value of the text box to sense mouse movements. function. There isjQuerycode~
For example, when the text box gets the mouse focus, the default value will be cleared. When there is no input content in the text box, the mouse focus leaves. time, it will return to the default value.
Code example:
The above code implementation In order to meet our requirements, here is a brief introduction to its implementation principle:
It is very simple, just register the focus and blurevent processingfunctions for the text box. When the text box gets the focus, If the content of the text box is the same as the default value, the text box will be cleared. When the focus leaves the text box, if the content of the text box is empty, it will be restored to the default value.
Or use the following code:
$('.default-value').each(function() { var default_value = this.value; $(this).focus(function(){ if(this.value == default_value) { this.value = ''; } }); $(this).blur(function(){ if(this.value == '') { this.value = default_value; } }); });
The above is the content of jQuery to implement the function of setting and removing the default value of the text box. For more information, please go toPHP Chinese websiteSearchOh~
Related recommendations:
##Detailed explanation of jQuery animation and special effects
Detailed explanation of the use of Jquery pop-up layer ThickBox plug-in
The above is the detailed content of jQuery implements the function of setting and removing the default value of text box. For more information, please follow other related articles on the PHP Chinese website!