JS 在文本框中输入特定单词会触发密码提示,输入正确后将引导至新页面
在文本框中输入特定单词会触发密码提示,输入正确后,您将被定向到新页面。
这是我到目前为止所拥有的。我可能偏离了目标,但我想让它以某种方式发挥作用。这只是为了好玩,在现实生活中确实没有帮助,但有人告诉我我做不到,所以现在我正在尝试。这就是我所拥有的。
<form id="form1">
<input type="text" id="txtInput" size="1" onblur="checkValue()" />
</form>
<script type="text/JavaScript">
function checkValue()
{
var txtCtrl = document.getElementById("txtInput");
var txtValue = txtCtrl.value;
if (txtValue == "test" || txtValue == "vgx" || txtValue == "vgc" || txtValue == "pcv" || txtValue == "pcg")
{
prompt('Enter Password','');
}
if (password != 'pass','password')
{
window.location.href='http://google.com';
}
}
</script>
我真的很抱歉我对 JS 的了解太差了,有点新。
非常感谢, 丹尼
Making a specific word entered into a textbox trigger a password prompt that when correctly entered, you are directed to a new page.
Here is what I have so far. I could be way off the mark, but I would like to make it work somehow. This is just for fun, and really does not help in real life, but someone told me I couldn't do it, so now I'm trying to. Here's what I have.
<form id="form1">
<input type="text" id="txtInput" size="1" onblur="checkValue()" />
</form>
<script type="text/JavaScript">
function checkValue()
{
var txtCtrl = document.getElementById("txtInput");
var txtValue = txtCtrl.value;
if (txtValue == "test" || txtValue == "vgx" || txtValue == "vgc" || txtValue == "pcv" || txtValue == "pcg")
{
prompt('Enter Password','');
}
if (password != 'pass','password')
{
window.location.href='http://google.com';
}
}
</script>
I'm really sorry I suck so much with JS, kinda new.
Many thanks,
Danny
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将不起作用,因为 Javascript 对客户端浏览器是可见的。也就是说,任何人都可以查看您页面的源代码并查看您的整个脚本,包括密码。
考虑使用数据库,或者至少从位于文档目录之外的文件中存储/检索密码。
This will not work because Javascript is visible to the client browser. That is, anyone can just view the source of your page and see your entire script, including the password.
Consider using a database, or at the very least store/retrieve your password from a file located outside of your document directory.