Home > Web Front-end > JS Tutorial > body text

jQuery implements the function of setting and removing the default value of text box_jquery

WBOY
Release: 2016-05-16 16:20:38
Original
1019 people have browsed it

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:

Copy code The code is as follows:





Script Home







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:

Copy code The code is as follows:

$('.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;
                }
});

});

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template