$(document).ready(function() {
$(document).display(none);
var password =("You have just entered a private website. Please enter the password to access it!");
if (password == "biology") {
$(document).display();
}
else {
window.location.replace("https://www.google.co.uk")
};
});
html {
background-image: url("bg.jpg")
}
body {
margin: 0 25%;
background-color: #ccc;
}
nav li {
padding-left: 5px;
border: solid 5px #aaa;
}
nav ul {
list-style-type: none;
position: fixed;
left: 9%;
font-size: 36px;
}
nav a {
color: #ccc;
text-decoration: none;
}
article {
background-color: white;
border: white solid #c0c;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="pl">
<head>
<title>Krystian Mikołajczyk</title>
<link href="style.css" rel="stylesheet" type="text/css">
<link href="jquery-2.1.1.js" type="text/javascript">
<link href="pass.js" type="text/javascript">
</head>
<body>
<header>
<h1 align="center"><i>Krystian Mikołajczyk</i></h1>
</header>
<nav>
<ul><i>
<li><a href="#">Home</a></li>
<li><a href="#">Uploads</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">Contact</a></li>
</i></ul>
</nav>
<br>
<br>
<br>
<article>
<section>
<h1>Recent Update</h1>
</section>
</article>
</body>
</html>
我正在尝试为自己创建一个网站,我可以随时随地使用它,我想用密码保护它,特别是如果我要为自己保留一些下载和上传内容。
密码被认为是“生物学”,因为我希望我的生物老师在开发过程中为我上传一本pdf书。
我不知道我做错了什么,但提示信息不想出现,这就是我想知道的。
答案 0 :(得分:1)
您的代码中出现了一些错误。直接转到 working demo 。
$(document).display(none);
这是无效的,因为没有一个不是已定义的变量,要么删除它,要么使用替代方法:
$(document).css('display', 'none');
或
$(document.body).hide();
var password = ("You have just entered a private website. Please enter the password to access it!");
这不会做任何事情,但您可以使用提示方法来请求输入:
var password = prompt("You have just entered a private website. Please enter the password to access it!");
else {
window.location.replace("https://www.google.co.uk")
};
应该只是:
else {
window.location.replace("https://www.google.co.uk")
}
检查您的开发者工具是否确定。他们太棒了!
...由于您的密码以纯文本形式存储,并且通过查看客户端来源很容易找到,因此您无法接近安全。关于如何正确地散列密码,存储它们并将它们与用户的散列输入值进行比较有很多材料 - 但这是另一个故事。
答案 1 :(得分:0)
$(document).display(none);
你的意思是$(document).css('display', 'none');
。但是真的:
$(document.body).hide();
由于文档对象无法隐藏,hide()
更具可读性。
您将password
设置为长字符串:
var password =("You have just entered a private website. Please enter the password to access it!");
所以永远不会等于"biology"
。我相信你的意思是说:
var password = prompt("You have just entered a private website. Please enter the password to access it!");
最后,
$(document).display();
应该是:
$(document.body).show();
$(document.body).hide();
var password = prompt("You have just entered a private website. Please enter the password to access it!");
if (password == "biology") {
$(document.body).show();
} else {
window.location.replace("https://www.google.co.uk")
};
&#13;
html {
background-image: url("bg.jpg")
}
body {
margin: 0 25%;
background-color: #ccc;
}
nav li {
padding-left: 5px;
border: solid 5px #aaa;
}
nav ul {
list-style-type: none;
position: fixed;
left: 9%;
font-size: 36px;
}
nav a {
color: #ccc;
text-decoration: none;
}
article {
background-color: white;
border: white solid #c0c;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<header>
<h1 align="center"><i>Krystian Mikołajczyk</i></h1>
</header>
<nav>
<ul><i>
<li><a href="#">Home</a></li>
<li><a href="#">Uploads</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">Contact</a></li>
</i>
</ul>
</nav>
<br>
<br>
<br>
<article>
<section>
<h1>Recent Update</h1>
</section>
</article>
&#13;