我正在控制器中检查一个值。这是我的代码。
var contents = atob(response.documents);
// I checked the value in contents . it is displaying ""
if(contents === ""){
// no contents
}
当内容为空时,if条件返回false;当内容有数据时,if条件也返回false。如何检查这个条件?
我正在控制器中检查一个值。这是我的代码。
var contents = atob(response.documents);
// I checked the value in contents . it is displaying ""
if(contents === ""){
// no contents
}
当内容为空时,if条件返回false;当内容有数据时,if条件也返回false。如何检查这个条件?
好的纯JavaScript。
if(!contents){
}
那么 contents.trim().length === 0
怎么样?
在Javascript中,空字符串是假值,你可以使用:
if(contents){
//has content
}else{
//no content
}