BadGirl_Xiao

导航

JS 验证字符串是否为空

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
        function isEmpty(str){
            if(str===undefined){
                return true;
            }else if(str==null){
                return true;
            }else{
                var reg=/^\s*$/;
                return reg.test(str);
            }
        }
        while(true){
            var input=prompt("输入");
            if(!isEmpty(input)){
                document.write(input);
                break;
            }else{
                alert("输入不能为空")
            }
        }
    </script>
</body>
</html>

 

posted on 2017-08-01 14:32  BadGirl_Xiao  阅读(490)  评论(0编辑  收藏  举报