代码如下.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>
试下document.forms[0].user.value
<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>
加红的地方都多空格,用他的方法怎么能取到呢,把空格去掉。而且这位老兄这个问题不是第一次发帖了吧??
function check(){
var users=document.form.user.value;
if(users.length==0){
document.write( "请填写 ");
return false;
}
}