三个条件[已定义;字符串;不为空]
一般情况下,都可以使用
if((typeof str !=='undefined') && (typeof str === 'string') && str.length>0){
console.log('验证成功')
}else{
console.log('失败')
};
更严谨的情况下使用
if(((typeof str2 !=='undefined' && str2 !== 'null') && (typeof str2.valueOf() === 'string')) && str2.length>0){
console.log('验证成功')
}else{
console.log('失败')
};
网友评论