代码如下.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>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>
</form>
  </body>
</html>

解决方案 »

  1.   

    应该是JS有错误,把IE的脚本错误提示打开,在IE的高级设置里。没调试你的代码,猜测是document.form.user.value有错误。
    试下document.forms[0].user.value
      

  2.   

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