首页 > Web开发 > 详细

JS判断输入框值是否为空

时间:2016-02-29 16:01:39      阅读:179      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>JS判断输入框的值是否为空</title>
</head>
<body>
<input type="text" id="txt"/>
<input type="button" value="检测" id="btn">
<script>
    var oTxt = document.getElementById(txt);

    var oBtn = document.getElementById(btn);
    function isnull(val) {

        var str = val.replace(/(^\s*)|(\s*$)/g, ‘‘);//去除空格;

        if (str == ‘‘ || str == undefined || str == null) {
            //return true;
            console.log()
        } else {
            //return false;
            console.log(非空);
        }
    }

    oBtn.onclick = function () {

        isnull( oTxt.value );

    }

</script>
</body>
</html>

 

JS判断输入框值是否为空

原文:http://www.cnblogs.com/codinganytime/p/5227383.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!