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];
}

猜你喜欢

转载自www.cnblogs.com/root0/p/12172798.html
今日推荐