jquery check if empty

 When writing verification, it is necessary to perform verification when the input air value is not empty. The code is as follows

1  if ($("#email" ).val()) {
 2             var isEmail = /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-]) +(\.[a-zA-Z0-9_-])+/ ;  
 3             if (!isEmail.test($("#email" ).val())){
 4               $('#popContent').text ('Please enter the correct email address' );
 5               $('#popMask').modal('open' );
 6               return  false ;
 7             }
 8 }

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==""){

//code

}

(2) if(C.length==0){

//code

}

(3) if(C){

//code

}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325872889&siteId=291194637