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.
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.
In the test.html file, use the input tag to create an input box for content input.
In the test.html file, add an id attribute myinput to the input tag, which is used to obtain the input object below.
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.
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.
Open the test.html file in the browser and click the button to see the effect.
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!