JS如何判断输入框(就是text或textarea)的值只是空字符串或只带空格得字符串
请各位帮帮忙,如题的代码怎么写?谢谢。。
[解决办法]
/^\s+$/
[解决办法]
/^\s*$/
[解决办法]
- JScript code
var str=document.getElmentById("textbox1").value;if(/\S/.match(str)){ //不全是空格}
[解决办法]
- JScript code
var str = document.getElementById('txtid').value;if(/[^\s]+/.test(str)) alert('不全是空格,有其它字符')
[解决办法]
/^\s*$/
[解决办法]
- HTML code
<html><head><title>字符串为空或空格是不是一回事呢?</title> </head><script>function intp(){ var text = document.getElementById('intp').value; if(text=='') { alert("文本框中为空"); } else if(text.match(' ')) { alert("文本框的字符有空格") } else { alert(text); }}</script><body> <input id="intp" type="text" ></input> <input type="button" onclick="intp()" value="单击"></input></body></html>