且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

点击更改图像

更新时间: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);
        });
    });
});