定义一个图片数组,生成一个随机数对应数据索引。
window.onload = choosePic; function choosePic() { var myPix = new Array("images/lion.jpg","images/tiger.jpg","images/bear.jpg"); var randomNum = Math.floor((Math.random() * myPix.length)); document.getElementById("myPicture").src = myPix[randomNum]; }
原文地址:https://www.cnblogs.com/root0/p/12172798.html
时间: 2024-10-11 13:03:56