开发者

Display the form again?

I want to ask about the form in Javascript.

I want to do a game wh开发者_开发百科ere the user enters the correct word, then an alert message will appear for this correct word. When the user does the first word correct, the program will display another word (to be corrected). But the problem which I faced that I can't make the form display again to continue the game.

I used:

var d = document.getElementById("form1"); d.style.visibility = "visible";

but it doesn't work!

This is my code:

<head>
    <title>Word Decoder</title>
    <script type="text/javascript">
        function checkWord(word, score)
        {
            var ok = words[score].valueOf();
            var ok1 = document.getElementById("wordid");
            if(ok1.value == ok)
            {
                score ++;
                alert("Correct, your score is: " + score);
                var d = document.getElementById("form1");
                d.style.visibility = "visible";
                return false;
            } 
            else 
            {
                alert("Wrong Spelling");
                return false;
            }
        }
    </script>
</head>
<body>
    <script type="text/javascript">
        var words = new Array ("apple", "orange", "banana", "manago", "table");
        var reWords = new Array ("alpep", "ergano", "aaabnn", "goamna", "lbeat");
        var count = 0;
        var score = 0;
        "</br>";
    </script>
    <form id="form1">
        <br>
        <dir id="displayForm" 
                style="position: relative; 
                visibility: visible; 
                display: block">
            <h3><b> <script> document.write(reWords[score]);</script> </b></h3>
            <br>
            Enter the correct word: <input type="text" value="" id="wordid"/>
            <input type="submit" 
                    value="Check Answer ??" 
                    onclick="return checkWord(wordid, score);" />
        </dir>
    </form>
</body>

Again: I want the game will display a scrambled word and the user must unscrambled the word to move to the other word. The problem is I can't display the form again to make the user unscrambled the second, third etc. words.


Use d.style.display="none" to hide and d.style.display="block" to show.


Think your post got mangled, I don't see where you are hiding it in the first place.. Also, avoid using document.write if you don't need it... inject the element or use .innerHTML if you need to, but not document.write.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜