简体   繁体   English

无法使我的功能正常运行

[英]Can't get my function to act properly

Ok, so I'm having a hard time with functions not working with the rest of my code. 好的,所以我在处理其他代码无法使用的功能时遇到了麻烦。 I've checked for spelling errors, tried debugging, ect. 我检查了拼写错误,尝试调试,等等。 My button (makeSong) that is supposed to run the song "Ants go marching down" with verses and chorus, but when I push the button on the page it just stays the same. 我的按钮(makeSong)应该运行带有诗歌和合唱的歌曲“ Ants go mardown down”,但是当我按页面上的按钮时,它保持不变。 Why is this happening? 为什么会这样呢? Functions have been giving me a really difficult time. 函数给了我一个非常困难的时期。 I hope I explained my question well, this is only my second question and I am a self taught newbie. 我希望我能很好地解释我的问题,这只是我的第二个问题,我是一个自学成才的新手。 So if you guys could take a look and maybe explain why my code isn't right. 因此,如果你们可以看看并解释我的代码为什么不正确。 Am I putting the functions in the wrong place? 我将功能放置在错误的位置吗? I'm confused. 我糊涂了。

<!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> 

2 things: 2件事:

in the HTML change this line 在HTML中更改此行

<button type="button" onclick="makeSong">

to

<button type="button" onclick="makeSong();">

typo in the js at the beginning of the makeSong function: 在makeSong函数开头的js中输入错误:

ouput=document.getElementById("output");

the "t" is missing ou t put “T”型缺少OU 牛逼

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM