Home >Web Front-end >JS Tutorial >How to determine if jquery is empty
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}].
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!