日期:2014-05-16 浏览次数:20517 次
var str=document.getElmentById("textbox1").value;
if(/\S/.match(str))
{
//不全是空格
}
------解决方案--------------------
var str = document.getElementById('txtid').value;
if(/[^\s]+/.test(str)) alert('不全是空格,有其它字符')
------解决方案--------------------
/^\s*$/
------解决方案--------------------
<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>