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

韦小宝
Release: 2017-11-28 10:00:32
Original
1352 people have browsed it

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:

    程序员之家   

Copy after login

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; } }); });
Copy after login

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

About the secret of jQuery

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!

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!