如果使用jquery,请不要接受或设置条件

如果使用jquery,请不要接受或设置条件,jquery,Jquery,我正在使用jquery进行表单验证。但我的if条件不起作用。contry3的值为“未定义”。 我的代码如下 var country3=$('.shorttext2').val(); alert(country3); if(country3 =='' || country3 =='undefined') { alert("Please Add Country."); return false; } 有人帮我吗?应该是 if (typeof country3 == "

我正在使用jquery进行表单验证。但我的if条件不起作用。contry3的值为“未定义”。 我的代码如下

var country3=$('.shorttext2').val();
alert(country3);

 if(country3 =='' || country3 =='undefined')
 {
    alert("Please Add Country."); 
    return false;  
 }
有人帮我吗?

应该是

if (typeof country3 == "undefined" || country3 =="") {
一个简单的版本是

 if(!country3)
 { 
     //not defined, or is empty
 }
或者只要检查(!country3){}