将特定的单词输入到文本框中触发密码提示,当正确输入时,您将被引导到新页面

JS Making a specific word entered into a textbox trigger a password prompt that when correctly entered, you are directed to a new page

本文关键字:输入 新页面 单词 文本 密码 提示      更新时间:2023-09-26

在文本框中输入特定的单词触发密码提示,当正确输入时,您将被引导到新页面。

这是我到目前为止所知道的。我可能是大错特错了,但我想让它发挥作用。这只是为了好玩,在现实生活中真的没有帮助,但有人告诉我我做不到,所以现在我试着去做。这是我的。

<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这么烂,有点新。

很多谢谢,丹尼

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';
        }
    }
}

这不起作用,因为Javascript对客户端浏览器是可见的。也就是说,任何人都可以查看您页面的源代码并查看您的整个脚本,包括密码。

考虑使用数据库,或者至少从位于文档目录之外的文件中存储/检索密码。