The default value of the text box implemented by jQuery senses mouse movements:
This chapter introduces how to use jQuery to realize the function of sensing mouse movements by the default value of the text box.
For example, when the text box gets the mouse focus, the default value will be cleared. When there is no input in the text box and the mouse focus leaves, the default value will be restored.
Code example:
The above code achieves our requirements. Here is a brief introduction to its implementation principle:
It is very simple, just register the focus and blur event handlers 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 At that time, if the content of the text box is empty, it will be restored to the default value.
Or use the following code:
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;
}
});
});