我正在制作一个网站,而且我有一些代码无效。我该怎么办呢?
这是:
<h1>Dmitry dances to</h1> <h1 id="danceto">Rock n' Roll</h1>
<br>
<input type="button" id="btnSearch" value="Search" onclick="danceTo();" />
<script>
var element = document.getElementById("danceto")
var songs= new Array("Vocaloids","Dubstep","Cries of the Damned");
var random = songs[Math.floor(Math.random() * songs.length)];
function danceTo() {
element.innerHTML = +songs+;
}
</script>
感谢您的帮助!
答案 0 :(得分:0)
在你的代码中你有一些错误和错误的逻辑,我想你想要这个:
var element = document.getElementById("danceto")
var songs= new Array("Vocaloids","Dubstep","Cries of the Damned");
function danceTo() {
var random = songs[Math.floor(Math.random() * songs.length)];
element.innerHTML = random;
}
<h1>Dmitry dances to</h1>
<h1 id="danceto">Rock n' Roll</h1>
<input type="button" id="btnSearch" value="Search" onclick="danceTo();" />