诸位。。麻烦帮我看看。。我对了半天没找到问题出在哪里。我用dreamweaver画的jsp页面都无法调用js。直接就跳上action了。每个页面都是我眼睛花了。高分,,高分求解脱<%@ page language="java" 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>
<style>
#userName{width:150px}
#userPass{width:150px}
#validateCode{width:150px}
</style>  <head>
    <base href="<%=basePath%>">
    
    <title>用户登录</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">
-->
  </head>
  <script type="text/javascript">
  function checkLogin(){
    var userName=document.getElementById("userName").value;
    var userPass=document.getElementById("userPass").value;
    
    if(userName==""){
       alert("帐号必填!");
       return false;
    }else if(userPass==""){
      alert("密码必填!");
      return false;
    }else{
      return true;
    }}  </script>
  
  <body>
    <center>
    <br />
  <div align="center" ><h1><font color="#9999FF">用户登录</font></h1></div>
<br />
  <hr align="center" />
<br />   <form action="user-login" method="post">
    <table  border="0"  height="100">
 
        <tr>
            <td>${notice}</td>
          </tr>
 
         <tr align="left" bgcolor="#9999FF" >
            <td>用户名:<input type="text" name="user.userName"></td>
         </tr>
  
         <tr align="left" bgcolor="#9999FF">
            <td>密&nbsp;&nbsp;码  :<input type="password" name="user.userPass"></td>
         </tr>
  
         <tr align="left" bgcolor="#9999FF">
            <td>验证码:<input type="text" name="validateCode"/></td>
          </tr>
       
          <tr align="left" bgcolor="#9999FF">
            <td>
                <img id="codeImg" src="validateCode-getCode" alt="点我就变!" 
                onClick="javascript:window.location.reload()">
                                                     看不清?点图片
            </td>
          </tr>
  
         <tr align="center" bgcolor="#9999FF">
            <td colspan="2" align="center">
               <input type="submit" value="登录" onclick="return checkLogin()">
               <input type="reset" value="重置"/>
       <a href="<%=basePath%>jsp/updPass1.jsp">忘记密码?</a>
         </tr>
  
     </table>
  </form>
      
</center>
  </body>
</html>

解决方案 »

  1.   

    你js里面是getElementById("userName")取得ID值为userName的
    但是在你的input中,只有name是userName,根本没有ID,肯定找不到。
    password与userName一样,修改一下就好了!
      

  2.   

    在补充一点,你应该判断userName.length==0和userPass.length==0
    你判断的是userName=="",这不安全,如果数据一个空格,你的判断形同虚设。还有,不要使用<input type="submit">在IE下没有问题,如果在火狐下面,即使JS判断了,也会直接提交的,你这样写.....条件判断
    如果都成立
    $('form1').action=提交路径;
    $('form1').submit();这里的form1可以随便起,就是在form中加上一个name属性
    跟你的name="user.userName" 意思一样。
      

  3.   

    ......真是晚上了,我也眼晕了。把input type="submit"  修改成 input type="button"