我想用一些js保护我的本地静态html网站的密码,这样当我在pc中打开我的本地html文件时,它会附带一个表单来填写我的用户id和我自己的密码,我已经保存了密码,当我点击enter键时,应该会打开我的索引。仅当密码正确时才使用html文件。目前我的代码是
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<Form>
<!-- user-id -->
<input type="text">
<!-- user-password -->
<input type="password">
<button onclick="window.open('./index.html')"> Enter
</button>
</Form>
<script>
// pls-help-me-idk-how-to-code-js
</script>
</body>
</html> ``
首先,您必须向该输入添加id或类,以便在脚本部分中选择它们。之后,您可以选择它们并添加您想要的任何值。例如:
<form>
<!-- user-id -->
<input id="user" type="text" />
<!-- user-password -->
<input id="pass" type="password" />
<button onclick="window.open('./index.html')">Enter</button>
</form>
<script>
document.getElementById("user").value = "UsernameOrId";
document.getElementById("pass").value = "SomePassword";
</script>
为了进行比较,您应该从数据库或服务之类的地方获得正确的密码,但由于这纯粹是为了学习,您可以在脚本中硬编码以进行检查。因此,最终的解决方案可以类似于此:
<body>
<form>
<!-- user-id -->
<input id="user" type="text" />
<!-- user-password -->
<input id="pass" type="password" />
<button id="btn">Enter</button>
</form>
<script>
const myPass = "SomePassword";
document.getElementById("user").value = "UsernameOrId"; // predefining the value simulating is saved and by default filled up
document.getElementById("pass").value = myPass; // predefining the value simulating is saved and by default filled up
const btn = document.getElementById("btn"); // getting the button to control its behavior on click event
btn.addEventListener("click", function () {
const passWhenClickingTheBtn = document.getElementById("pass").value;
if (myPass === passWhenClickingTheBtn) { // checking the value entered for pass
window.open("./index.html");
}
});
</script>
这不是一个正确的方法。为了正确执行,您需要一个后端。但如果只是为了玩,你可以有一个警告框,比较它们的值:如果正确,它会显示出来。
但我需要一个解释,因为代码的工作方式与预期的不同。 我想在我的网站上有一个链接,用户可以点击whatsapp链接,开始与联系人的对话。 我添加的代码是这样的: null 这段代码在Android和iPhone上都可以使用,但它不允许我添加自定义联系号码: abid只能是已保存在您手机中的联系人的ID,否则它将打开whatsapp中的联系人选择页面 请不要在没有内容解释的情况下分享链接,因为我不是一
Edge:(Mozilla/5.0(Windows NT 6.1;Win64;x64)AppleWebKit/537.36(KHTML,like Gecko)Chrome/83.0.4103.97 Safari/537.36 EDG/83.0.478.45) 其中4个浏览器的共同点是Chrome和Safari关键字接受FireFox,但android上的FireFox在userAgent字符串中显
当我在浏览器上输入我的网站网址时,我的网站没有打开,而是在下载我的页面。问题是什么?
以下是错误: 警告:需要(/home/****/public_html/wp-包含/load.php):无法打开流:第21行 /home/growfi5/public_html/wp-settings.php中没有这样的文件或目录 致命错误:require():无法打开required'/home/**/public\u html/wp includes/load。php'(include_pat
使用CSRF保护,这样从其他网站发出的任何请求都不会影响我的网站造成伤害。在Spring安全csrf留档中说,csrf应用于放帖补丁删除请求。 但据我了解,登录/注册表单不需要csrf保护,因为它们已经需要用户名和密码形式的凭据,即使是从另一个网站发出这样的请求,也不会有任何伤害,因为用户只需登录即可。 但是由于登录通常是一个发布请求,csrf将在Spring默认情况下自动应用。这意味着我需要将c
我想启用 - 从字面上看 - GCC的所有警告。(你会认为这很容易... > < li> 您可能会认为-Wall可能会成功,但事实并非如此!你仍然需要-Wextra。 你会认为可能会成功,但没有!并非此处列出的所有警告(例如-Wshadow)都由此启用。我仍然不知道这个列表是否全面。 我如何告诉GCC启用(没有if,and,or but!)它拥有的所有警告?