Home >Web Front-end >JS Tutorial >How to determine if jquery is empty

How to determine if jquery is empty

coldplay.xixi
coldplay.xixiOriginal
2020-12-11 10:33:172149browse

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;
           }
}

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==""){
//代码
}

(2)

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

(3)

if(C){
//代码
}

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!

Statement:
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