-1

可能重复:
密码 HTML 重定向

所以我有这个代码,我需要它只在添加正确密码时重定向。唯一的问题是我不知道要添加什么只会在密码为“hello”时重定向我知道使用“view-source”会显示密码,我不介意,这是我想要的方式. 我基本上只需要知道要添加什么以及在哪里添加它。

Sooo:如果在密码字段中输入“hello”,则重定向。如果将其他任何内容放入密码字段,则不执行任何操作。

<div class="wrapper">

    <form class="form1" action="http://google.com">

        <div class="formtitle">Enter the password to proceed</div>

        <div class="input nobottomborder">
            <div class="inputtext">Password: </div>
            <div class="inputcontent">

                <input type="password" />
                <br/>

            </div>
        </div>

        <div class="buttons">

            <input class="orangebutton" type="submit" value="Login" />


        </div>

</div>  

我希望这很清楚并且可以理解。

更新:输入密码以继续

    <div class="input nobottomborder">
        <div class="inputtext">
            Password:
        </div>

        <div class="inputcontent">
            <input type="password" id="password" /><br />
        </div>
    </div>

    <div class="buttons">
        <input class="orangebutton" type="submit" value="Continue" onclick="if (document.getElementById('password').value == 'hello') location.href='members.html'; else alert('Wrong Password!');" />
    </div>
</form>

​​​

4

2 回答 2

2

您将不得不使用 javascript。您只需要登录按钮上的事件侦听器,然后检查输入字段的值并重定向。使用普通的 javascript 很简单,但使用 jQuery 更容易。它应该是这样的(但我没有测试代码)。

$('.orangebutton').click(function () {
    if ($('input:password').val() == "hello") {
        window.location.href = "http://stackoverflow.com";
    }
});

当然,您必须包含 jquery 库并确保加载了 dom。

于 2012-10-08T15:08:26.047 回答
0

解释

我在这里使用的代码是:

if (document.getElementById('password').value == 'hello')
    alert('Correct Password!');
else
    alert('Wrong Password!');

现在对于您的问题,我们可以alert('Correct Password!');location.href='members.html'或其他东西代替。

if (document.getElementById('password').value == 'hello')
    location.href='members.html';
else
    alert('Wrong Password!');

看一下这个。没用过jQuery,纯JavaScript

<div class="wrapper">
    <form class="form1" action="http://google.com">
        <div class="formtitle">
            Enter the password to proceed
        </div>

        <div class="input nobottomborder">
            <div class="inputtext">
                Password:
            </div>

            <div class="inputcontent">
                <input type="password" id="password" /><br />
            </div>
        </div>

        <div class="buttons">
            <input class="orangebutton" type="submit" value="Login" onclick="if (document.getElementById('password').value == 'hello') alert('Correct Password!'); else alert('Wrong Password!');" />
        </div>
    </form>
</div>​

在这里摆弄:http: //jsfiddle.net/AmMwQ/

于 2012-10-08T15:21:19.533 回答