我正在使用jquery进行表单验证。但是我的if条件不起作用.contry3的值是'undefined'。 我的代码如下:
var country3=$('.shorttext2').val();
alert(country3);
if(country3 =='' || country3 =='undefined')
{
alert("Please Add Country.");
return false;
}
有人帮帮我吗?
答案 0 :(得分:1)
那应该是
if (typeof country3 == "undefined" || country3 =="") {
简单版本
if(!country3)
{
//not defined, or is empty
}