js随机显示图片
作者:互联网
定义一个图片数组,生成一个随机数对应数据索引。
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]; }
标签:var,jpg,js,myPix,randomNum,随机,images,Math,图片 来源: https://www.cnblogs.com/root0/p/12172798.html