JS 在文本框中输入特定单词会触发密码提示,输入正确后将引导至新页面

发布于 2024-11-29 22:30:31 字数 713 浏览 1 评论 0原文

在文本框中输入特定单词会触发密码提示,输入正确后,您将被定向到新页面。

这是我到目前为止所拥有的。我可能偏离了目标,但我想让它以某种方式发挥作用。这只是为了好玩,在现实生活中确实没有帮助,但有人告诉我我做不到,所以现在我正在尝试。这就是我所拥有的。

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

高跟鞋的旋律 2024-12-06 22:30:31
function checkValue()
{
    var txtCtrl = document.getElementById("txtInput");

    var txtValue = txtCtrl.value;

    if (txtValue == "test" || txtValue == "vgx" || txtValue == "vgc" || txtValue == "pcv" || txtValue == "pcg")
    {
        var password = prompt('Enter Password','');

        if (password == 'pass') 
        { 
            window.location.href='http://google.com';
        }
    }
}
function checkValue()
{
    var txtCtrl = document.getElementById("txtInput");

    var txtValue = txtCtrl.value;

    if (txtValue == "test" || txtValue == "vgx" || txtValue == "vgc" || txtValue == "pcv" || txtValue == "pcg")
    {
        var password = prompt('Enter Password','');

        if (password == 'pass') 
        { 
            window.location.href='http://google.com';
        }
    }
}
旧故 2024-12-06 22:30:31

这将不起作用,因为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文