第1个回答 2019-11-17
/**
* 判断是否是空
* @param value
*/
function isEmpty(value){
if(value == null || value == "" || value == "undefined" || value == undefined || value == "null"){
return true;
}
else{
value = value.replace(/\s/g,"");
if(value == ""){
return true;
}
return false;
}
}
第2个回答 2021-06-21
下面这种应该是使用最广的
var a = document.querySelector('video');//必须有这一行这设置的,否则全都会报not defined
// console.log(a);null
if ((a == "") || (a == undefined) || (a == null)) {
alert("数据为空");//会跳到这里
} else {
alert("数据不不不不不不为空");
}
a =="" ||undefined || null
有些情况会有问题,例如
var a = document.querySelector('video');//必须有这一行这设置的,否则全都会报not defined;上面没有视频的
if ( a == "" || undefined || null) {
alert("数据为空");
}else{
alert("数据正确");//回调到这里
};
第3个回答 2019-08-12
function (obj) {
let type = Object.prototype.toString.call(obj).slice(8, -1);
switch (type) {
case 'String':{
if (obj.length > 0) {
let r = obj.toUpperCase() !== 'NULL';
if (r){
r = obj.toUpperCase() !== 'UNDEFINED';
}
return r;
}
return false;
}
case 'Object':
return Object.keys(obj).length > 0;
case 'Array':
return type.length > 0;
case 'Undefined':
return false;
case 'Null':
return false;
}
}
第4个回答 2013-12-27
<input type="text" id="name" value=“点击” onclick="checkNull()"/>
<script>
function checkNull(){
var name = document.getElementById("name").value.replace(/[]/g,"");//把所有空格去掉
if(name.length==0||name=="点击"){
alert("请输入数据!");
}
}
</script>本回答被提问者和网友采纳