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

How to determine if jquery is empty

coldplay.xixi
coldplay.xixiOriginal
2020-11-17 15:59:103333browse

Jquery method to determine whether it is empty: 1. Method one [if(C==null||C==undefined||C=="")]; 2. Method two [if(C. length==0)]; 3. Method three [if (C) {//code}].

How to determine if jquery is empty

Jquery method to determine whether it is empty:

It needs to be used when writing verification when the input empty value is not When it is empty, perform verification, 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 jquery method of judging whether it is empty

var C = $("类名或者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