代码如下.JS不验证直接提交, 谢各位大大 <%@ page language= "java " import= "java.util.* " pageEncoding= "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 'a.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 language= "javascript ">
function check(){
var users=document.form.user.value;
if(users==null){
document.write( "请填写 ");
return false;
}
}
</script>
</head>
<body>
<form method= "post " name= "form " action= "a.jsp " onSubmit= "return check() " > <p>
<input type= "text " name= "user "> <input type= "submit " name= "connect "> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p>
</form>
</body>
</html>
<%
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 'a.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 language= "javascript ">
function check(){
var users=document.form.user.value;
if(users==null){
document.write( "请填写 ");
return false;
}
}
</script>
</head>
<body>
<form method= "post " name= "form " action= "a.jsp " onSubmit= "return check() " > <p>
<input type= "text " name= "user "> <input type= "submit " name= "connect "> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p>
</form>
</body>
</html>
var users=document.form.user.value;
if(users==""){
alert("请填写");
return false;
}
}
试试,users==null是不正确的哦.
<%
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 'a.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 language= "javascript ">
function check(){
var users=document.getElememtById("user").value;
if(users==""){
document.write( "请填写 ");
return false;
}
}
</script>
</head>
<body>
<form method="post"name="form"action="a.jsp"onSubmit="return check()">
<p>
<input type= "text" id = "user" name= "user">
<input type= "submit" value="提交" >
</p></form>
</body>
</html>
<html>
<head>
<title>js</title>
<script>
function check(){
var users=document.form.user.value;
if(users.length==0){
document.write("请填写");
return false;
}
}
</script>
</head>
<body>
<form method="post" name= "form" action="1.html" onSubmit="return check()" > <p>
<input type= "text" name= "user"> <input type= "submit" name="connect"> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p>
</form>
</body>
</html>