用正则匹配空格和换行符,将他替换删除,判断剩下的值length==0
var str = " /n/n/n" var text = str.replace(/s+|[ ]/g,"") if(text.length==0){ console.log("当前str为空") }