我無法獲取用於清除文本的按鈕。所以當我點擊圖片時,按鈕和文本會顯示,當我點擊按鈕時,它會消失,但文本不會。按下按鈕時清除段落文本
<script type="text/javascript">
function song(animal, sound) {
document.getElementById("buttonAppear").innerHTML = '<button type="button" onclick="buttonFunction(); clear();">Clear</button>';
document.getElementById("verse").innerHTML += "<br>Old MacDonald had a farm, E-I-E-I-O.<br>And on that farm he had a " + animal + ", E-I-E-I-O.<br>with a " + sound + "-" + sound + " here and a " + sound + "-" + sound + " there,<br> here a " + sound + " there a " + sound + " everywhere a " + sound + "-" + sound + ".";
}
function clear() {
document.getElementById("verse").innerHTML = "";
}
function buttonFunction() {
document.getElementById("buttonAppear").innerHTML = "";
}
</script>
</head>
<main>
<h1>The Animals Game</h1>
<img src="cat.jpg" title="Cat" alt="Cat" height="200" width="200" onclick="song('CAT', 'MEOW') ;">
<img src="cow.jpg" title="Cow" alt="Cow" height="200" width="200" onclick="song('COW', 'MOO') ;">
<img src="dog.jpg" title="Dog" alt="Dog" height="200" width="200" onclick="song('DOG', 'WOOF') ;">
<p id="verse"></p>
<div id="buttonAppear"></div>
呃,哪兒的按鈕? –