<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
<title>JS判断输入框不能为空</title>
<script language="Javascript">
<!--
function checkChinese()
{ var isnumandchar;
var StrForCheck=form_key.keywords.value;
var c;
c = StrForCheck.charAt(0);
while((c ==" "||c ==" ") && StrForCheck.length > 0)
{
StrForCheck = StrForCheck.slice(1);
c = StrForCheck.charAt(0);
}
c = StrForCheck.charAt(StrForCheck.length -1);
while((c ==" "||c ==" ") && StrForCheck.length > 0)
{
StrForCheck = StrForCheck.substring(0,StrForCheck.length-1);
c = StrForCheck.charAt(StrForCheck.length -1);
}
form_key.keywords.value = StrForCheck;//如果没有值,继续
if (StrForCheck.length==0 || StrForCheck.length<2)
{
if (StrForCheck.length==0) {alert("注意:输入框不能为空!");return false;}
}
else
{return true;}
}
//-->
</script>
</head>
<body>
<form method="POST" name="form_key" onsubmit="return checkChinese();">
<input name="keywords" size="30" class="editbox1">
<input type=submit value=" 发 送 " class=bottom name="submit">
</form>
</body>
</html></td>
</tr>
</table>