在本地,我正在尝试使用类似于数据库的 XML 页面来匹配登录凭据。如果登录凭据匹配,它必须进入下一页,该页面将是包含某些内容的新 HTML 页面。这是我到目前为止在 HTML 和 XML 页面中所拥有的内容。我使用 JavaScript 进行了验证,并为一位用户进行了硬编码。在 XML 中,如果我有 10 个用户,那我该怎么办?
<html>
<head><title>Login page</title></head>
<body>
<div align="right">
<h1 style="font-family:Times New Roman;text-align="center";font-size:20pt;
color:#00FF00;>
Welcome to Login Page
</h1>
<form name="login">
Username:   <input type="text" name="userid"/><br><br>
Password:   <input type="password" name="paasword"/><br><br>
<input type="button" onclick="check(this.form)" value="Login"/>
<input type="reset" value="Cancel"/>
</form>
<script language="javascript">
function check(form)/*function to check userid & password*/
{
/*the following code checkes whether the entered userid and password are matching*/
if(form.userid.value == "user1" && form.password.value == "pass1")
{
window.open('success.html')/*opens the target page while Id & password matches*/
}
else
{
alert("wrong Username or Password")/*displays error message*/
}
}
</script>
</div>
</body>
</html>
XML 代码:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<student>
<details>
<username>user1</username>
<password>pass1</password>
<email>user1@abc.com</email>
</details>
<details>
<username>user2</username>
<password>pass2</password>
<email>user2@abc.com</email>
</details>
<details>
<username>user3</username>
<password>pass3</password>
<email>user3@abc.com</email>
</details>
<details>
<username>user4</username>
<password>pass4</password>
<email>user4@abc.com</email>
</details>
</student>