我有这段代码,用于更改随机重新加载的每个页面上显示的图像。我在 JavaScript 方面不是很有经验,所以有人可以帮我让这段代码在重新加载时按顺序而不是随机更改图像吗?
这是代码:
function showImage(){
var theImages = new Array()
theImages[0] = '100.jpg'
theImages[1] = '200.jpg'
theImages[2] = '300.jpg'
theImages[3] = '400.jpg'
theImages[4] = '500.png'
var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}
然后我简单地用这个来调用身体中的图像:
showImage();