jquery判断是否为空的方法:1、使用undefined判断,代码为【if(C==null||C==undefined||C==""){//代码}】;2、判断长度大小,代码为【if(C.length==0){//代码}】。



本教程操作环境:windows7系统、jquery3.2.1版本,该方法适用于所有品牌电脑。

推荐:jquery视频教程

jquery判断是否为空的方法:

写校验时需要用到当input空中值不为空时,执行校验,代码如下

1

2

3

4

5

6

7

8

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;

           }

}

也趁机会总结一下jquery判断是否为空的方法

var C = $("类名或者id").val();

(1)

1

2

3

if(C==null||C==undefined||C==""){

//代码

}

(2)

1

2

3

if(C.length==0){

//代码

}

(3)

1

2

3

if(C){

//代码

}

相关免费学习推荐:javascript(视频)

更多推荐

jquery怎么样判断是否为空