更新时间:2023-12-03 11:13:16
您需要使用索引
递增1而不是随机。 在达到数组长度时重置
索引。
You need to use index
incremented by 1 instead of random. Reset
index when it reaches array length.
var images = ["02.jpg","03.jpg","01.jpg"];
$(function() {
index = 0;
$('.change').click(function(e) {
var image = images[index++];
if(index == images.length)
index = 0;
$('#bg').parent().fadeOut(200, function() {
$('#bg').attr('src', 'items/'+image);
$(this).fadeIn(200);
});
});
});