Closed 。这个问题需要多问focused /help/closed-questions 。目前不接受答案。
(小心,英语不好)
我正在尝试创建一个页面,其中只有一个“小块”,您可以在其中键入我设置的密码。
如果您输入正确的密码并按“输入站点”按钮,您将进入下一页。
这不必是一个完全受保护的网站,只需一个 1 行表单,如果输入的密码正确,它会将您发送到 html 代码中指定的页面。
我是我学校的一年级学生,非常喜欢使用 html,但由于我远远领先于班上的其他同学,我想了解更多,所以我希望有人可以帮助我。
提前致谢!
这是我在photoshop中制作的一个例子 https://i.stack.imgur.com/PrDZp.jpg
仅 HTML 无法做到这一点,您需要在后端使用其他语言来检查密码。或者您可以使用 javascript,它将在前端验证密码,但只有当您这样做是为了好玩时,您才必须在代码本身中指定密码。否则,要开发带有登录页面的 Web 应用程序,您需要后端语言(例如 php 或 python)和数据库(例如 mysql 或 mariadb)来存储密码。
示例代码 您需要创建两个文件,一个用于登录表单 (login.html),另一个用于在输入正确密码后重定向 (welcome.html)。
此代码用于login.html
<!DOCTYPE html>
<html>
<head>
<title>Login page</title>
</head>
<body>
<form>
<label for="pswd">Enter your password: </label>
<input type="password" id="pswd">
<input type="button" value="Submit" onclick="checkPswd();" />
</form>
<!--Function to check password the already set password is admin-->
<script type="text/javascript">
function checkPswd() {
var confirmPassword = "admin";
var password = document.getElementById("pswd").value;
if (password == confirmPassword) {
window.location="welcome.html";
}
else{
alert("Passwords do not match.");
}
}
</script>
</body>
</html>
此代码用于welcome.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome page</title>
</head>
<body>
<h1>Welcome!! you entered a right password</h1>
</body>
</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)