文章目录
一、题目要求
制作一个登录表单,输入账号和密码,如果账号和密码相等,则显示“登录成功”,否则显示“登录失败”。
二、代码实现
5-1.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>登陆表单</title>
</head>
<body>
登陆表单
<script type="text/javascript">
function validate() {
if (loginForm.account.value=="") {
alert("账号不能为空!");
return; }
if (loginForm.password.value=="") {
alert("密码不能为空!");
return; }
if (loginForm.account.value==loginForm.password.value) {
alert("登陆成功!!");
return; }
if (loginForm.account.value!=loginForm.password.value) {
alert("登陆失败!!");
return; }
loginForm.submit();
}
</script>
<form name="loginForm" method="post" action="target.jsp">
输入账号:<input type="text" name="account"/><br />
输入密码:<input type="password" name="password" /><br />
<input type="button" value="登录" onclick="validate()" />
</form>
</body>
</html>
三、运行结果