Home > Web Front-end > JS Tutorial > How to determine whether input is empty in jquery

How to determine whether input is empty in jquery

王林
Release: 2020-11-30 16:03:58
Original
5337 people have browsed it

The jquery method to determine whether the input is empty: first create the isempty function; then obtain the input object through the id within the function; then use the val method to obtain the input content; finally use the if statement and use the length attribute to determine Can.

How to determine whether input is empty in jquery

The operating environment of this tutorial: Windows 10 system, jquery version 2.2.4. This method is suitable for all brands of computers.

(Learning video sharing: jquery video tutorial)

The method is as follows:

Create a new html file and name it test.html.

How to determine whether input is empty in jquery

In the test.html file, use the input tag to create an input box for content input.

How to determine whether input is empty in jquery

In the test.html file, add an id attribute myinput to the input tag, which is used to obtain the input object below.

How to determine whether input is empty in jquery

In the test.html file, create a button button, bind the onclick click event to the button, and when the button is clicked, execute the isempty() function.

How to determine whether input is empty in jquery

In the js tag, create the isempty() function. Within the function, obtain the input object through the id, use the val() method to obtain the input content, and then use the if statement , use the length attribute to determine the content length of the input. If the content length is not greater than 0, the input content is empty.

How to determine whether input is empty in jquery

Open the test.html file in the browser and click the button to see the effect.

How to determine whether input is empty in jquery

For more programming-related knowledge, please visit: Programming Learning! !

The above is the detailed content of How to determine whether input is empty in jquery. 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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template