0
好的,所以我很難與其他代碼不兼容的功能。我檢查了拼寫錯誤,嘗試調試等。我的按鈕(makeSong)應該用詩句和合唱來運行歌曲「螞蟻走下去」,但是當我按下頁面上的按鈕時,它就保持不變。這是爲什麼發生?功能一直給我一個非常困難的時間。我希望我能很好地解釋我的問題,這只是我的第二個問題,我是一個自學成才的新手。所以如果你們可以看看,也許可以解釋爲什麼我的代碼是不正確的。我是否把這些功能放在錯誤的地方?我很困惑。無法讓我的功能正常工作
<!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>
嘗試''makeSong在onclick屬性()。 – doldt
另外'#output'可能會影響全局'output'變量。 – Teemu
提示:您的拼寫錯誤檢查不成功。看看你的'makeSong'函數。 – chazsolo