js判斷字段是否爲空 isNull 兩種方法

1.//在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({}));       //falseio

 

2.function

var parm = *****class

if(!!parm){di

  

}co

!表明非 表明否認return

!!表明確定undefined

相關文章
相關標籤/搜索