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

How to determine if jquery is empty

coldplay.xixi
Release: 2021-01-08 17:42:32
Original
2128 people have browsed it

Jquery method to determine whether it is empty: 1. Use undefined to determine, the code is [if(C==null||C==undefined||C==""){//code}]; 2. To determine the length, the code is [if(C.length==0){//code}].

How to determine if jquery is empty

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, thinkpad t480 computer.

Recommended: jquery video tutorial

##jquery method to determine whether it is empty:

When writing verification, you need to perform verification when the input value is not empty. The code is as follows

if($("#email").val()) {
           var isEmail = /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
           if(!isEmail.test($("#email").val())){
             $('#popContent').text('请您输入正确的邮箱');
             $('#popMask').modal('open');
             return false;
           }
}
Copy after login

I also take the opportunity to summarize the method of jquery to determine whether it is empty

var C = $("class name or id").val();

(1)

if(C==null||C==undefined||C==""){
//代码
}
Copy after login

(2)

if(C.length==0){
//代码
}
Copy after login

(3)

if(C){
//代码
}
Copy after login

Related free learning recommendations: javascript(Video)

The above is the detailed content of How to determine if jquery is empty. 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