Javascript中的多个函数
Multiple Functions in Javascript
本文关键字:函数 Javascript 更新时间:2023-09-26
很
抱歉,如果这是一个非常愚蠢的问题,我对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>
感谢您的帮助!
document
对象中已经有一个名为 clear
的函数。将函数命名为其他名称。
字符串有换行符,您可以删除它们或在每行末尾添加'
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
工作,那就奇怪了。
编辑:显然文档对象中有一个清晰的方法
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()
函数重命名为其他名称。我将其更改为 clearDesc()
并且工作正常(修复字符串中的换行问题后)。看这里。
<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/
相关文章:
- 从函数JavaScript返回不可变数组/对象
- 将对象传递给函数.JavaScript
- 如何定义const函数javascript(语法糖)
- 新的日期函数javascript
- TypeError:this.getAttribute不是一个函数-javascript
- 从函数javascript发送变量
- 扩展自容器函数Javascript
- 从内部函数javascript内部分配外部函数的对象
- 使用函数JavaScript中的函数
- 在这里使用回调函数(JavaScript)有什么好处吗
- 来自函数 Javascript 的 NaN 返回值 ||函数执行顺序
- 将“e”传递给一个新函数 - javascript
- 调用函数中的一个函数——Javascript
- 传递的变量不适用于我的函数-Javascript
- 如何将类方法设置为等于多个函数?-Javascript
- 显示php中的函数javascript
- 如何使用php代码创建函数Javascript弹出框
- 未调用的外部函数-javascript
- 如何在类中运行函数.Javascript
- 关闭mouseover上的一个函数——Javascript,jQuery