好的,所以我很难将函数与其余的代码一起使用。我检查了拼写错误,尝试过调试等。我的按钮(makeSong)应该用歌词和合唱来播放歌曲“Ants go down down”,但是当我按下页面上的按钮时它就保持不变。为什么会这样?功能给了我一个非常困难的时间。我希望我能很好地解释我的问题,这只是我的第二个问题而且我是一个自学新手。所以,如果你们可以看看,也许可以解释为什么我的代码不正确。我把功能放在了错误的地方吗?我很困惑。
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8"></meta>
<title>AntsFunction.html</title>
<script type="text/javascript">
// from AntsFunction.html
var output;
function chorus(){
var text= "...and they all go marching down<br/>";
text += "to the ground<br/>";
text += "to get out<br/>";
text += "of the rain.<br/>";
text += "<br/>";
text += "boom boom boom boom boom boom boom boom<br/><br/>";
output.innerHTML += text;
} // end chorus
function verse1(){
var text= "The ants go marching 1 by 1 hurrah, hurrah<br/>";
text += "The ants go marching 1 by 1 hurrah, hurrah<br/>";
text += "The ants go marching 1 by 1<br/>";
text += "The little one stops to suck his thumb<br/><br/>";
output.innerHTML += text;
} // end verse1
function verse2(){
var text= "The ants go marching 2 by 2 hurrah, hurrah<br/>";
text += "The ants go marching 2 by 2 hurrah, hurrah<br/>";
text += "The ants go marching 2 by 2<br/>";
text += "The little one stops to tie his shoe<br/><br/>";
output.innerHTML += text;
} // end verse2
function makeSong(){
ouput=document.getElementById("output");
output.innerHTML="";
verse1();
chorus();
verse2();
chorus();
} // end makeSong
</script>
</head>
<body>
<h1>Using Basic Functions</h1>
<form action="">
<fieldset>
<button type="button"
onclick="makeSong">
Make Song
</button>
</fieldset>
</form>
<div id="output">
The song will appear here...
</div>
</body>
</html>
答案 0 :(得分:0)
2件事:
HTML中的更改此行
<button type="button" onclick="makeSong">
到
<button type="button" onclick="makeSong();">
makeSong函数开头的js中的拼写错误:
ouput=document.getElementById("output");
&#34; t&#34;缺少ou t put