2

如果这是一个非常愚蠢的问题,我很抱歉,我对 JavaScript 有点陌生。我正在尝试制作一个包含多个功能的网页,但只有第一个功能会成功。我在谷歌上搜索,我只得到一次调用多个函数的结果,但这不是我想要的。这是我正在尝试做的一个例子:

<html>
    <head>
        <script type="text/javascript">
            function frogger()
            {
                document.getElementById("descriptions").innerHTML="Frogger <br />Description: Get
                    the frog to the islands at the top of the screen without falling into the water or
                    getting hit by cars. <br />Controls: Up arrow key to move forward, down arrow key to
                    move backward, left arrow key to move left, and right arrow key to move right.";
            }
            function clear()
            {
                document.getElementById("descriptions").innerHTML=" ";
            }
        </script>
    </head>
    <body>
        <div id="descriptions" style="{height:100;}">
        </div>
        <div class="game" onmouseover="frogger()" onmouseout="clear()">
            <a href="/arcade/frogger.html"><img border="0" src="http://ggmedia.site50.net
/pics/frogger.PNG" height="100" width="100" /><br />Frogger</a>
        </div>
    </body>
</html>

感谢您的帮助!

4

5 回答 5

6

对象中已经有一个命名cleardocument函数。将您的功能命名为其他名称。

于 2012-06-03T01:13:08.533 回答
2

您的字符串有换行符,您可以删除它们或\在每行的末尾添加一个

function frogger()
{
    document.getElementById("descriptions").innerHTML="Frogger <br />Description: Get\
the frog to the islands at the top of the screen without falling into the water or\
getting hit by cars. <br />Controls: Up arrow key to move forward, down arrow key to\
move backward, left arrow key to move left, and right arrow key to move right.";
}

​ 编辑:如果您更改clear函数的名称以说它clearx有效,那就奇怪了。

编辑:显然在文档对象中有一个 clear 方法

于 2012-06-03T01:10:12.433 回答
2
function frogger() {
    document.getElementById("descriptions").innerHTML="Frogger <br />Description: Get the frog to the islands at the top of the screen without falling into the water or getting hit by cars. <br />Controls: Up arrow key to move forward, down arrow key to move backward, left arrow key to move left, and right arrow key to move right.";
}
于 2012-06-03T01:12:18.280 回答
0

将函数重命名为clear()其他名称。我将其更改为clearDesc()并且工作正常(在修复字符串中的换行问题之后)。见这里

于 2012-06-03T01:13:54.080 回答
0
  <div class="game" onmouseover="frogger()" onmouseout="clearr()">mousee</div>
    <div id="descriptions"></div>
    <script type="text/javascript">
        var frogger = function () {
            this.innerHTML = ["Frogger <br />Description: Get}",
                    "the frog to the islands at the top of the screen without falling into the water or",
                    "getting hit by cars. <br />Controls: Up arrow key to move forward, down arrow key to",
                    "move backward, left arrow key to move left, and right arrow key to move right."].join('');
        }.bind(document.getElementById("descriptions"));
        //
        var clearr = function () {
            this.innerHTML = " ";
        }.bind(document.getElementById("descriptions"));

    </script>

这是 jsfiddle.net 中的代码

http://jsfiddle.net/gerst20051/6Neqv/

于 2012-06-03T01:52:19.723 回答