var myArray = ['A','B','C'];
document.getElementById("button").onclick = function() {
if (myArray.length > 0) {
var a = Math.floor(Math.random() * myArray.length);
var b = myArray.splice(a, 1);
document.getElementById("showRand").innerHTML = b[0];
} else {
//restart
}
}
<button id="button">click</button>
<div id="showRand"></div>
Onclick时,它随机清空myArray,如何重新填充数组,然后在myArray为空时重复该过程?
感谢您的帮助..
心有法竹
相关分类