首页 > 语言 > JavaScript > 正文

js检测输入内容全为空格的方法

2024-05-06 16:05:01
字体:
来源:转载
供稿:网友
这篇文章主要介绍了js检测输入内容全为空格的方法,,需要的朋友可以参考下

JavaScript判断输入内容不能全为空格的方法,用来避免输入框的内容输入的全是空格:

复制代码 代码如下:


<html>
 <head>
  <script>
   function checkBlankSpace(str){
    while(str.lastIndexOf(" ")>=0){
      str = str.replace(" ","");
    }
    if(str.length == 0){
     alert("输入不能全为空");
    }
   }
   function test(){
    var testStr = document.getElementById("test").value;
    checkBlankSpace(testStr);
   }
  </script>
 </head>
 <body>
  <input type="text"/>
  <input type="button" value="测试">
 </body>
</html>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选