如果这是一个非常愚蠢的问题,我很抱歉,我对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>
感谢您的帮助!
答案 0 :(得分:5)
clear
对象中已有一个名为document
的函数。将你的功能命名为别的。
答案 1 :(得分: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
它的工作原理,那很奇怪。
编辑:显然文档对象中有一个清晰的方法
答案 2 :(得分: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.";
}
答案 3 :(得分:0)
将clear()
函数重命名为其他内容。我将其更改为clearDesc()
并且工作正常(在修复字符串中的换行符问题之后)。请参阅here。
答案 4 :(得分: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中的代码