myeclipse jsp 验证的时候在提交表单的时候总是验证出错!但我已经验证了,但前台验证总是不提示呀!
<%@pagelanguage="java"import="java.util.*"contentType="text/html;charset=UTF-8"%><%St...
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'lts.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script src="scripts/trim.js"></script>
</head>
<body>
<h1 align="center">欢迎来到侃大山聊天室!</h1>
<hr color="red">
<table border="1" align="center">
<form name="form1" action="lts1.jsp" method="post" onsubmit="return check()">
<tr><td><b>昵称:</b></td><td><input name="username" size="10" maxlength="10"></td></tr>
<tr ><td colspan="2" align="center"><input type="submit" name="denglu" value="登 陆" ></td></tr>
</form>
</table>
</body>
</html>
<script>
function check(){
//alert("");
var username=form1.username.value.Trim();
if(username==""){
alert("昵称不能为空,你必须输入");
form1.username.value="";
form1.username.focus();
return false;
}
if(username.length<3){
alert("昵称不能小于三个字符");
form1.username.value="";
form1.username.focus();
return false;
}
return true;
}
</script> 展开
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'lts.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script src="scripts/trim.js"></script>
</head>
<body>
<h1 align="center">欢迎来到侃大山聊天室!</h1>
<hr color="red">
<table border="1" align="center">
<form name="form1" action="lts1.jsp" method="post" onsubmit="return check()">
<tr><td><b>昵称:</b></td><td><input name="username" size="10" maxlength="10"></td></tr>
<tr ><td colspan="2" align="center"><input type="submit" name="denglu" value="登 陆" ></td></tr>
</form>
</table>
</body>
</html>
<script>
function check(){
//alert("");
var username=form1.username.value.Trim();
if(username==""){
alert("昵称不能为空,你必须输入");
form1.username.value="";
form1.username.focus();
return false;
}
if(username.length<3){
alert("昵称不能小于三个字符");
form1.username.value="";
form1.username.focus();
return false;
}
return true;
}
</script> 展开
1个回答
展开全部
可能是你form1.username.value.Trim();语句出的错误,写成这样form1.username.value就可以验证,你可以这样试一试是不是语句里有异常
function check(){
//alert("");
var username;
try{
username=form1.username.value.Trim();
}catch(error){
alert(error);
}
if(username==""){
alert("昵称不能为空,你必须输入");
form1.username.value="";
form1.username.focus();
return false;
}
if(username.length<3){
alert("昵称不能小于三个字符");
form1.username.value="";
form1.username.focus();
return false;
}
return false;
}
function check(){
//alert("");
var username;
try{
username=form1.username.value.Trim();
}catch(error){
alert(error);
}
if(username==""){
alert("昵称不能为空,你必须输入");
form1.username.value="";
form1.username.focus();
return false;
}
if(username.length<3){
alert("昵称不能小于三个字符");
form1.username.value="";
form1.username.focus();
return false;
}
return false;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询