
小程序前台怎么判断是空白消息
方法:可以封装个判断对象为空的函数,如下面代码中isBlank。
function isBlank(str){
if (Object.prototype.toString.call(str) ==='[object Undefined]'){//空
return true
} else if (
Object.prototype.toString.call(str) === '[object String]' ||
Object.prototype.toString.call(str) === '[object Array]') { //字条串或数组
return str.length==0?true:false
} else if (Object.prototype.toString.call(str) === '[object Object]') {
return JSON.stringify(str)=='{}'?true:false
}else{
return true
}
}登录后复制使用isBlank对消息进行为空判断:
if(isBlank(message)){
console.log('消息为空')
}else{
console.log('消息:' + message)
}登录后复制PHP中文网,大量免费小程序开发教程,欢迎学习!
以上就是小程序前台怎么判断是空白消息的详细内容,更多请关注靠谱客其它相关文章!

最后
以上就是隐形春天最近收集整理的关于小程序前台怎么判断是空白消息的全部内容,更多相关小程序前台怎么判断是空白消息内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复