JSP文件:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page contentType="text/html; charset=gb2312"%>
<%@page import="java.io.*,java.sql.*"%>
<html>
<head>
<title>登录页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<script type="text/javascript" language="JavaScript" src="checkBlank.js"  >
</script>
<body>
<table width="1000" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="120" colspan="5">
      <img src="pic/logobanner.gif" width="1000" height="120" alt="">
    </td>
  </tr>
  <tr>
    <td height="340" colspan="5">
      <img src="pic/pic_2.gif" alt="" name="picture" width="1000" height="340" id="picture">
    </td>
  </tr>
  <tr>
    <td width="200" height="60">
    <form name="linkform" method="post" action="">
      <div align="center">
        <select name="select" size="1">
          <option>----友情链接----</option>
          <option value="http://www.u.edu.cn">学校主页</option>
          <option value="http://www.baidu.com">百度收索</option>
        </select>
      </div>
    </form>
    </td>
    <td width="800" height="60" bgcolor="#006699">&nbsp;</td>
  </tr>
  <tr>
    <td width="200" height="60" align="center" valign="top" bgcolor="#CCCCCC">
      <p align="center">
        <font size="+1" face="Times New Roman, Times, serif">Date:</font>
      </p>
      <p align="center">
<script language="JavaScript" src="datejavascript.js" type="text/JavaScript">
</script>      </p>
    </td>
    <td height="60" valign="bottom" bgcolor="#CCCCCC">
    <form action="handleLogOn.jsp" name="logOnForm" method="post">
      <p align="center">        &nbsp;&nbsp;
        身份:
        <select size=1 class="INPUTBOX" style="border-width:2px;border-style:Solid;" name="selectType">
          <option value="老师">教师
          <option value="管理员">管理员
        </select>
        &nbsp;&nbsp;&nbsp;
        帐号:
        <input type="text" size="12" class="INPUTBOX" style="border-width:1px;border-style:Solid;" name="userName" id="用户名">
        &nbsp;&nbsp;&nbsp;
        密码:
        <input type="password" name="pwd" size="12" value="" class="INPUTBOX" style="border-width:1px;border-style:Solid;" id="密码">
        &nbsp;&nbsp;&nbsp;
        <input type="submit" value="登 录" name="loginBtn" style="border-width:1px;border-style:Solid;" onclick="checkBlank(logOnForm)">
        &nbsp;&nbsp;&nbsp;
        <input type="reset" value="重 置" name="resetBtn" style="border-width:1px;border-style:Solid;">    </form>
    </td>
  </tr>
  <tr bgcolor="#006699">
    <td height="20" colspan="5">
      <div align="center">
        <font color="#99CC00">
          建议使用1024*768的分辨率,IE6.0
          Copyrights
          &copy;
          2005 by SCIE of UESTC All rights reserved
</font>
      </div>
    </td>
  </tr>
</table>
</body>
</html>各位达人帮我,分大大的有!

解决方案 »

  1.   

    把<script type="text/javascript" language="JavaScript" src="checkBlank.js"  >
    </script>
    这段放到body 的form中间试试
      

  2.   

    是在同一目录啊,放在form中了,还是不行啊
      

  3.   

    将<script type="text/javascript" language="JavaScript" src="checkBlank.js"  ></script>
    改为<script language="JavaScript" src="checkBlank.js"></script>
    将 type="text/javascript"去掉
      

  4.   

    <head>
    .......
    <script language="JavaScript" src="checkBlank.js"></script>
    .......
    </head>
      

  5.   

    这是改了过后的JS文件:
    ----------------------------------
    function checkBlank(current_form) {    var missing_fields = new Array();
        var total_missing = 0    // Loop through all the form elements
        for (counter = 0; counter < current_form.length; counter++) {
    //alert(current_form[counter].mandatory)
            // Is this a visible text field that's mandatory?
            if ((current_form[counter].type == "text" ||
                current_form[counter].type == "textarea" ||
                current_form[counter].type == "password") &&
                current_form[counter].mandatory) {
    //alert(its_empty(current_form[counter].value))
                // Is it empty?
                if (its_empty(current_form[counter].value)) {                // If so, add the field to the array of missing fields
                    missing_fields[total_missing] = current_form[counter]
                    total_missing++
                }
            }
        }    // Were there any fields missing?
        if (total_missing > 0) {        // Start the message
            var missing_message = "请填写:";
            // Loop through the missing fields
            for (counter = 0; counter < missing_fields.length; counter++) {
                missing_message += missing_fields[counter].id + "\n"
            }        //display the message
                alert(missing_message)        // For emphasis, put the focus on the first missing field
            missing_fields[0].focus()
        }
        else {        // Otherwise, go ahead and submit
            current_form.submit()
        }
    }function its_empty(string_value) {    // Check for the empty string and null
        if (string_value == "" || string_value == null) {        // If either, it's empty so return true
            return true
        }    // Otherwise, it's not empty so return false
        return false
    }
    ----------------------------------------
    这是改了后的JSP文件
    ----------------------------------------
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <%@page contentType="text/html; charset=gb2312"%>
    <%@page import="java.io.*,java.sql.*"%>
    <html>
    <head>
    <title>登录页面</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <script  type="text/JavaScript" language="JavaScript" src="checkBlank.js"  ></script>
    <body>
    <table width="1000" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="120" colspan="5">
          <img src="pic/logobanner.gif" width="1000" height="120" alt="">
        </td>
      </tr>
      <tr>
        <td height="340" colspan="5">
          <img src="pic/pic_2.gif" alt="" name="picture" width="1000" height="340" id="picture">
        </td>
      </tr>
      <tr>
        <td width="200" height="60">
        <form name="linkform" method="post" action="">
          <div align="center">
            <select name="select" size="1">
              <option>----友情链接----</option>
              <option value="http://www.u.edu.cn">学校主页</option>
              <option value="http://www.baidu.com">百度收索</option>
            </select>
          </div>
        </form>
        </td>
        <td width="800" height="60" bgcolor="#006699">&nbsp;</td>
      </tr>
      <tr>
        <td width="200" height="60" align="center" valign="top" bgcolor="#CCCCCC">
          <p align="center">
            <font size="+1" face="Times New Roman, Times, serif">Date:</font>
          </p>
          <p align="center">
    <script language="JavaScript" src="datejavascript.js" type="text/JavaScript">
    </script>      </p>
        </td>
        <td height="60" valign="bottom" bgcolor="#CCCCCC">
        <form action="handleLogOn.jsp" name="logOnForm" method="post">
          <p align="center">        &nbsp;&nbsp;
            身份:
            <select size=1 class="INPUTBOX" style="border-width:2px;border-style:Solid;" name="selectType">
              <option value="老师">教师
              <option value="管理员">管理员
            </select>
            &nbsp;&nbsp;&nbsp;
            帐号:
            <input mandatory="true" type="text" size="12" class="INPUTBOX" style="border-width:1px;border-style:Solid;" name="userName" id="用户名">
            &nbsp;&nbsp;&nbsp;
            密码:
            <input mandatory="true" type="password" name="pwd" size="12" value="" class="INPUTBOX" style="border-width:1px;border-style:Solid;" id="密码">
            &nbsp;&nbsp;&nbsp;
            <input type="button" value="登 录" name="loginBtn" style="border-width:1px;border-style:Solid;" onclick="checkBlank(logOnForm)">
            &nbsp;&nbsp;&nbsp;
            <input type="reset" value="重 置" name="resetBtn" style="border-width:1px;border-style:Solid;">    </form>
        </td>
      </tr>
      <tr bgcolor="#006699">
        <td height="20" colspan="5">
          <div align="center">
            <font color="#99CC00">
              建议使用1024*768的分辨率,IE6.0
              Copyrights
              &copy;
              2005 by SCIE of UESTC All rights reserved
    </font>
          </div>
        </td>
      </tr>
    </table>
    </body>
    </html>
      

  6.   

    JS中的如下语句多了个“+”号,要报JS错误
    var missing_message = "请填写:" +JSP中的
    <input mandatory="true" type="text" size="12" class="INPUTBOX" style="border-width:1px;border-style:Solid;" name="userName" id="用户名">

    <input mandatory="true" type="password" name="pwd" size="12" value="" class="INPUTBOX" style="border-width:1px;border-style:Solid;" id="密码">
    中要加上
    mandatory="true" 属性用以告诉JS脚本,要对此表单元素进行验证因为在JS里有如下脚本代码:
    ... ...
            if ((current_form[counter].type == "text" ||
                current_form[counter].type == "textarea" ||
                current_form[counter].type == "password") &&
                current_form[counter].mandatory) {  //mandatory 表单元素中自定义的属性... ... 
      

  7.   

    好,问题解决!多谢温健兄.我想再多问一句,如果提交按钮的onclick事件我有多个JS要放进去,有的是要弹出一个alert之类的,有的则可能要返回一个boolean,那应该怎么写进去呢?格式怎样?例如:
    ..........
    function a ()
    {
    alert("ok")
    }
    ..........
    function b()
    {
    ............
    return false}..................onclick="???????"