如何在小程序前端识别是否为空消息内容?
- 内容介绍
- 文章标签
- 相关推荐
本文共计294个文字,预计阅读时间需要2分钟。
小程式前台如何判断是空白消息+方法:可以封装个判断对象为空的函数,如下面代码中的isBlank函数。例如下面的代码中的isBlank函数。
javascriptfunction isBlank(str) { if (Object.prototype.toString.call(str)==='[object Undefined]') { // 空的返回true return true; } else { // 其他情况返回false return false; }}
小程序前台怎么判断是空白消息
方法:可以封装个判断对象为空的函数,如下面代码中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中文网,大量免费小程序开发教程,欢迎学习!
以上就是小程序前台怎么判断是空白消息的详细内容,更多请关注自由互联其它相关文章!
本文共计294个文字,预计阅读时间需要2分钟。
小程式前台如何判断是空白消息+方法:可以封装个判断对象为空的函数,如下面代码中的isBlank函数。例如下面的代码中的isBlank函数。
javascriptfunction isBlank(str) { if (Object.prototype.toString.call(str)==='[object Undefined]') { // 空的返回true return true; } else { // 其他情况返回false return false; }}
小程序前台怎么判断是空白消息
方法:可以封装个判断对象为空的函数,如下面代码中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中文网,大量免费小程序开发教程,欢迎学习!
以上就是小程序前台怎么判断是空白消息的详细内容,更多请关注自由互联其它相关文章!

