<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<%@ page import="com.user.UserBean"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>登陆页面</title>
<script type="text/javascript" language="JavaScript">
function Check() {
var username = document.getElementById("username");
var password = document.getElementById("password");
if (username.Value == "") {
alert("用户名不能为空!");
return false;
} else if (password.Value == "") {
alert("密码不能为空!");
return false;
}
}
</script>
</head>
<body> <center>
<h1>欢迎来到原创教务系统</h1>
</center>
<form action="LoginAction.do" method="post" onSubmit="return Check();">
<table width="298" border="1" align="center" cellpading="4"
cellspacing="1">
<tr>
<td width="20%" align="left">用户类型&nbsp;&nbsp;:</td>
<td width="80%"><select name="userKind">
<option value="student">学生</option>
<option value="teacher">教师</option>
</select></td>
</tr>
<tr>
<td width="20%" align="left">用&nbsp;&nbsp;户&nbsp;&nbsp;名:</td>
<td><input width="80%" type="text" name="username"
id="username" size="15"
></td>
</tr>
<tr>
<td width="20%" align="left">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:</td>
<td><input width="80%" type="password" name="password"
id="password" size="15"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="登录">
</tr>
</table>
</form>
</body>
</html>
为什么在这里无法执行javascript脚本语句,在onSubmit="return Check()"这句这里提示Cannot return from outside a function or method.,该怎样去修改?????

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>登陆页面</title>
    <script type="text/javascript" language="JavaScript">
    function Check() {
    var username = document.getElementById("username");
    var password = document.getElementById("password");
    if (username.value == "") {
    alert("用户名不能为空!");
    return false;
    }
    if (password.value == "") {
    alert("密码不能为空!");
    return false;
    }
    }
    </script>
    </head>
    <body><center>
    <h1>欢迎来到原创教务系统</h1>
    </center>
    <form action="LoginAction.do" method="post" onSubmit="return Check();">
    <table width="298" border="1" align="center" cellpading="4" cellspacing="1">
    <tr>
    <td width="20%" align="left">用户类型&nbsp;&nbsp;:</td>
    <td width="80%"><select name="userKind">
    <option value="student">学生</option>
    <option value="teacher">教师</option>
    </select></td>
    </tr>
    <tr>
    <td width="20%" align="left">用&nbsp;&nbsp;户&nbsp;&nbsp;名:</td>
    <td><input width="80%" type="text" name="username" id="username" size="15"></td>
    </tr>
    <tr>
    <td width="20%" align="left">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:</td>
    <td><input width="80%" type="password" name="password" id="password" size="15"></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><input type="submit" value="登录">
    </tr>
    </table>
    </form>
    </body>
    </html>
      

  2.   

    value 注意大小写if else if 逻辑上有点问题。
      

  3.   

    最好把js写到body后面去,一面getbyid的时候得不到。
      

  4.   

    这是Myeclips的一个BUG,这个不影响运行,可以用9.x的版本就没有这个问题。