美文网首页
2019-03-27检测存在,且非空的字符串

2019-03-27检测存在,且非空的字符串

作者: 泡沫双鱼座 | 来源:发表于2019-03-27 18:12 被阅读0次

    三个条件[已定义;字符串;不为空]

    一般情况下,都可以使用

    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('失败')

    };

    相关文章

      网友评论

          本文标题:2019-03-27检测存在,且非空的字符串

          本文链接:https://www.haomeiwen.com/subject/jvjtbqtx.html