Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:50:06
Original
1169 people have browsed it

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

复制代码 代码如下:


 
  <script><BR> function checkBlankSpace(str){<BR> while(str.lastIndexOf(" ")>=0){<BR> str = str.replace(" ","");<BR> }<BR> if(str.length == 0){<BR> alert("输入不能全为空");<BR> }<BR> }<BR> function test(){<BR> var testStr = document.getElementById("test").value;<BR> checkBlankSpace(testStr);<BR> }<BR> </script>
 
 
  
  
 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!