判断undefined:
var tmp = undefinedif (typeof(tmp) == "undefined"){ alert("undefined")}
说明:typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"
判断null:
var tmp = nullif (!tmp && typeof(tmp)!="undefined" && tmp!=0){ alert("null")}
判断NaN:
var tmp = 0/0if(isNaN(tmp)){ alert("NaN")}
附上全部相等图≅:松散等于等于检查(==), 比如: "1" == true[] =="0"
=:全等或恒等全等检查(===)
var a = ""if (a =="" ||undefined || null) {
alert("数据为空")
}else{
alert("数据正确")
}
这样就可以!希望能帮到你~
//判断字符是否为空的方法isEmpty(obj){
var regu = "^[ ]+$"
var re = new RegExp(regu)
if(typeof obj == "undefined" || obj == null || obj == "" || re.test(obj)){
return true
}else{
return false
}
},
用法:
if(this.isEmpty(this.keyword)){
console.log('空字符')
}