1. 程式人生 > >js判斷字段是否為空 isNull

js判斷字段是否為空 isNull

isnull amp blog {} clas word eof function 表達

//在js中if條件為null/undefined/0/NaN/""表達式時,統統被解釋為false,此外均為true .
//為空判斷函數
function isNull(arg1)
{
return !arg1 && arg1!==0 && typeof arg1!=="boolean"?true:false;
}


//alert(isNull(null)); //true
//alert(isNull(‘‘)); //true
//alert(isNull()); //true
//var aa={};
//alert(isNull(aa.a)); //true
//alert(isNull(0)); //false
//alert(isNull(‘0‘)); //false
//alert(isNull(true)); //false
//alert(isNull("undefined")); //false
//alert(isNull(undefined)); //true
//alert(isNull([])); //false
//alert(isNull({})); //false

來自:http://blog.sina.com.cn/s/blog_68ead6830101cx3u.html

js判斷字段是否為空 isNull