JSP:我的一个表单中只有一个文本框和一个Submit,如果文本框中没有输入,则禁止提交,怎么做呢?

来源:百度知道 编辑:UC知道 时间:2024/07/07 16:22:21
怎么在jsp中禁止提交空值?文本框如果没有填写,则禁止提交,怎么做?
javascript做?

Submit 中加入javascript方法。例如:
验证输入框不为空

<html >
<head >
<title >传参数 </title >
<script language= "javascript " >
function check(){
var ch1=document.form1.text.value;
if(ch1.lenth==0 ¦ ¦ch1== " "){
alert( "请输入! ");
return false;
}
else
return true;
}
</script >
</head >
<body >
<form name= "form1 " action= "1.jsp " method= "get " onSubmit= "check() " >
<input type= "text " name= "text " >
<input type= "submit " name= "submit " >
</form >
</body >
</html >

文本框:txt
提交:tijiao

if (document.form1.txt.value=="")
{
alert("error