HTML / Js正确运行脚本

时间:2014-06-23 03:05:38

标签: javascript html function input password-protection

我正在为我的网站制作一些HTML。我想从个人信息中创建一个密码页面。就是这样:

<!doctype html>
<html>
<center>Password Protection</center>
<p></p>

"Gavin, psst, Gavin. Gavin, psst, Gavin. ______, ______, what? ______, ______, what?" <br><input type="text" id="answer1" value=""><p>
    "This boy thinks that bombs are made of ______!" <br><input type="text" id="answer2" value=""><p>
"I've got many fake books, since I'm a leprechaun farmer who's a ______"<br>
<form onsubmit="return compare()">
<input type="text" id="answer3" value=""><br>
<input type="submit" value="Submit">
</form>
<script type="text/javascript">

                        function compare()
                        {
                            var answer11 = "shut up"
                            var answer22 = "cheese"
                            var answer33 = "gambler"
                            var answer1 = document.getElementById("answer1")
                            var answer2 = document.getElementById("answer2")
                            var answer3 = document.getElementById("answer3")
                            if (answer1 == answer11){
                                var question1 = true
                            }
                            if (answer2 == answer22){
                                var question2 = true
                            }
                            if (answer3 == answer33){
                                var question3 = true
                            }
                            if (question1 = true, question2 = true, question3 = true){
                                window.open("webpage name")
                            }
                            else{
                                confirm("Incorrect")
                            }
                        }
                        </script>
<p>
<p>
</html>

我终于让代码本身部分工作了。即使您没有输入正确的内容,也可以在按下按钮时自动将您带到网页,而不是验证答案。有什么帮助吗?

编辑:

        {
                            var answer11 = "shut up"
                            var answer22 = "cheese"
                            var answer33 = "gambler"
                            var answer1 = document.getElementById("answer1")
                            var answer2 = document.getElementById("answer2")
                            var answer3 = document.getElementById("answer3")
                            if (document.getElementById("answer1" == answer11){
                                var question1 = true
                            }
                            if (document.getElementById("answer2").value; == answer22){
                                var question2 = true
                            }
                            if (document.getElementById("answer3").value; == answer33){
                                var question3 = true
                            }
                            if (question1 = true, question2 = true, question3 = true){
                                window.open("www.roadrunnersoccer.com/cole/info/banana.html")
                            }
                            else{
                                confirm("Incorrect")
                            }
                            return false;
                        }

1 个答案:

答案 0 :(得分:2)

var answer1 = document.getElementById("answer1").value;
var answer2 = document.getElementById("answer2").value;
var answer3 = document.getElementById("answer3").value;

您需要使用元素的值来与字符串进行比较,而不是元素本身。