function check(obj){
if(obj === null) console.log('Null')
if(obj == '') console.log('空字符串')
}
str = null
str1 = ''
check(str) //输出'Null'
check(str1) //输出'空字符串'
</script>
你给变量赋值了?var test = null
如果是这样定义,if(test==null)条件是成立的。
还是
var test
后就没再操作?如果这样做会弹出--undefined--。
或者你给test赋值了字符串 null 。
那就按照楼上的方法判断。
你对test变量做了什么?
var a = ""if (a =="" ||undefined || null) {
alert("数据为空")
}else{
alert("数据正确")
}
这样就可以!希望能帮到你~