<%@page contentType="text/html" pageEncoding="SHIFT_JIS" %>
<html>
<head>
<title>login</title>
</head>
<script language="javascript">
<%!
function sub()
{
String arg = document.getElementById("username").value;
String arg1 = document.getElementById("password").value;
String message = "";
if ((arg.equals("1")) && (arg1.equals("1"))) {
message = "success";
} else {
message = "failed";
}
application.setAttribute("Message",message);
document.Form.action = "message.jsp";
}
%>
</script>
<body>
<body bgcolor="white">
<h2>login</h2><p>
<form name="Form" method="post" action="" onSubmit="">
<table border=1 >
<tr>
<td width="80" align="center">username:
</td>
<td><input width="100%" type="text" id="username" name="username" />
</td>
</tr>
<tr>
<td width="80" align="center">password:
</td>
<td><input width="100%" type="password" id="password" name="password" maxLength="8" />
</td>
</tr>
</table><p>
<input type="submit" value="submit" onClick="sub();" />
</form>
</body>
sub()中为什么无法获取text id 为username,password的值?
<html>
<head>
<title>login</title>
</head>
<script language="javascript">
<%!
function sub()
{
String arg = document.getElementById("username").value;
String arg1 = document.getElementById("password").value;
String message = "";
if ((arg.equals("1")) && (arg1.equals("1"))) {
message = "success";
} else {
message = "failed";
}
application.setAttribute("Message",message);
document.Form.action = "message.jsp";
}
%>
</script>
<body>
<body bgcolor="white">
<h2>login</h2><p>
<form name="Form" method="post" action="" onSubmit="">
<table border=1 >
<tr>
<td width="80" align="center">username:
</td>
<td><input width="100%" type="text" id="username" name="username" />
</td>
</tr>
<tr>
<td width="80" align="center">password:
</td>
<td><input width="100%" type="password" id="password" name="password" maxLength="8" />
</td>
</tr>
</table><p>
<input type="submit" value="submit" onClick="sub();" />
</form>
</body>
sub()中为什么无法获取text id 为username,password的值?
var arg1 = document.getElementById("password").value;
<html>
<head>
<title> login </title>
</head>
<script language="javascript">
<%!
function sub()
{
String arg = document.getElementById("username").value;
String arg1 = document.getElementById("password").value;
String message = "";
if ((arg.equals("1")) && (arg1.equals("1"))) {
message = "success";
} else {
message = "failed";
}
application.setAttribute("Message",message);
document.Form.action = "message.jsp";
}
%>
</script>
<body>
<body bgcolor="white">
<h2> login </h2> <p>
<form name="Form" method="post" action="" onSubmit="">
<table border=1 >
<tr>
<td width="80" align="center"> username:
</td>
<td> <input width="100%" type="text" id="username" name="username" />
</td>
</tr>
<tr>
<td width="80" align="center"> password:
</td>
<td> <input width="100%" type="password" id="password" name="password" maxLength="8" />
</td>
</tr>
</table> <p>
<input type="submit" value="submit" onClick="sub();" />
</form>
</body>
sub()中为什么无法获取text id 为username,password的值?把上面红颜色的去掉试一试
<html>
<head>
<title> login </title>
</head>
<script language="javascript"> function sub()
{
String arg = document.getElementById("username").value;
String arg1 = document.getElementById("password").value;
String message = "";
if((arg=="1") and (arg1=="1"))
{
message = "success";
}else
{
message = "failed";
}
document.getElementById("Message").value=message;
document.Form.action = "message.jsp";
}
</script>
<body>
<body bgcolor="white">
<h2> login </h2> <p>
<form name="Form" method="post" action="" onSubmit="">
<table border=1 >
<tr>
<td width="80" align="center"> username:
</td>
<td> <input width="100%" type="text" id="username" name="username" />
</td>
</tr>
<tr>
<td width="80" align="center"> password:
</td>
<td> <input width="100%" type="password" id="password" name="password" maxLength="8" />
</td>
</tr>
</table> <p>
<input type="hidden" name="Message" value="">
<input type="submit" value="submit" onClick="sub();" />
</form>
</body>
</html>
我把你的这句:application.setAttribute("Message",message); 用隐藏域来代替,同样可以实现你的功能。
应该改为:if((arg=="1") && (arg1=="1"))
<%!
%>
删掉以后页面问题点击按钮仍然无法跳转至message.jsp页面,是不是点击按钮根本就没有调用sub()方法的原因,如果是如何解决啊