我在函数上有一个数组的array(allArr),第一次从allArr的位置0开始的数组是从位置0的图像中获取的,另一个数组具有图像(命名为image),这是因为document.ready然后单击按钮(来自allArr的id =“nextimageandshuffle”)数组和来自image array的图像达到第五个。我的问题是,每次单击下一个按钮时,我都必须用empty()清除div(id =“array”),其中将allArr的数组添加到其中append()但我无法在第5个数组后停止它,因此第5个图像(来自图像数组)保留在那里,但第5个数组(来自allArr)将其删除了...

这是我的代码:

var allArr;
var contor = 0;
var i = 0;

$(document).ready( function() {

    var arr = new Array("images/alfabet/w.png", "images/alfabet/f.png", "images/alfabet/v.png", "images/alfabet/a.png", "images/alfabet/b.png", "images/alfabet/p.png", "images/alfabet/o.png", "images/alfabet/r.png");
    var baiat = new Array("images/alfabet/p.png", "images/alfabet/b.png", "images/alfabet/a.png", "images/alfabet/aa.png", "images/alfabet/i.png","images/alfabet/a.png", "images/alfabet/t.png");
    var colac = new Array("images/alfabet/g.png", "images/alfabet/c.png", "images/alfabet/u.png", "images/alfabet/o.png", "images/alfabet/l.png", "images/alfabet/a.png", "images/alfabet/c.png");
    var slapi = new Array("images/alfabet/s.png", "images/alfabet/ss.png", "images/alfabet/l.png", "images/alfabet/a.png", "images/alfabet/b.png", "images/alfabet/p.png", "images/alfabet/i.png", "images/alfabet/i.png");
    var umbrela = new Array("images/alfabet/u.png", "images/alfabet/n.png", "images/alfabet/m.png", "images/alfabet/p.png", "images/alfabet/b.png", "images/alfabet/r.png", "images/alfabet/e.png", "images/alfabet/l.png", "images/alfabet/a.png");
    allArr = new Array(arr, baiat, colac, slapi, umbrela);
    for(i=0; i<allArr[0].length; i++)
    {
        var img = new Image();
                    img.src = allArr[0][i];
            $('#array').append(img);

        }
});

var image = new Array("images/baiat.png", "images/colac.png" , "images/slapi.png" , "images/umbrela.png");

var imgNumber=0;

var numberOfImg = image.length;

function nextImage(){
  if(imgNumber < numberOfImg){
    imgNumber++;
    }
  document.slideImage.src = image[imgNumber-1];

   contor++;

   $("#array").empty();


   for(i = 0; i<allArr[contor].length; i++)
    {
        var img = new Image();
        img.src = allArr[contor][i];
        $('#array').append(img);

    }


 }

if(document.images){

   var image1 = new Image();
   image1.src = "images/vapor.png";
   var image2 = new Image();
   image2.src = "images/baiat.png";
   var image3 = new Image();
   image3.src = "images/colac.png";
   var image4 = new Image();
   image4.src = "images/slapi.png";
   var image5 = new Image();
   image5.src = "images/umbrela.png";

   }

HTML:
<img src="images/vapor.png" name="slideImage" class='secondcanvas' width='450' height='300' alt="">
       <div id="array" class='thirdcanvas'></div>
<a href="#" onClick="nextImage()"><img id="nextimageandshuffle" src="images/nextBtn.png" title="Continuare" ></a>

最佳答案

我不确定我是否完全了解您要做什么,但是我想我明白了……

您将需要确定您是否在最后一张图像上,因为如果没有,您仍然希望清空该元素。将当前图像src与allArr [4] [4]中的字符串进行比较,如果它们匹配,则不要执行.empty()。因此,不仅是:

$("#array").empty();

您将需要用以下内容替换它:
if(img.src == allArr[4][4]){
    return;
}else{
    $("#array").empty();
}

09-25 20:56