isEmpty(obj){
var regu = "^[ ]+$"
var re = new RegExp(regu)
if(typeof obj == "undefined" || obj == null || obj == "" || re.test(obj)){
return true
}else{
return false
}
},
用法:
if(this.isEmpty(this.keyword)){
console.log('空字符')
}
<input name /><script>
var xx = document.getElementsByTagName('input')[0]
xx.onblur = function (){
if(xx.value=" "){
alert(1)
}
}
</script>
var str = "任意 字符串"if (str.indexOf(" ") == -1) {
alert("没有空格")
} else {
alert("有空格")
}