怎么在html网页上随机显示图片

2025-04-07 16:21:26
推荐回答(3个)
回答1:




666














window.onload = choosePic;

function choosePic() {
     var myPix = new Array("/img/01.png","/img/02.png","pics/2117.jpg","pics/2238.jpg");
    var randomNum = Math.floor((Math.random() * myPix.length));
    document.getElementById("myPicture").src = myPix[randomNum];
}

回答2:

你写的代码,能发全吗,还是给写一个新的

回答3:

需要js配合