我如何发布 X 数量的图像,其中 X = 随机数。在这个例子中,我设置了 X=10
<input class="randombutton" type="button" value="Randomize" onclick="randomImg1" />
<script type="text/javascript">
function randomImg1() {
myImages1 = new Array();
for (var i = 0; i < 10; i++){
myImages1.push("MyImage" + i + ".jpg");
}
var rnd = Math.floor(Math.random() * 10);
document.getElementById("image").innerHTML = "<img src='" + myImages1[rnd] + "' alt='image' />";
}
randomImg1();
</script>
<div id="image"></div>
</body>
</html>