加载图像后,将Custom Server Control src放入jQuery数组中



我正在尝试创建一个服务器控件,该控件在加载某个类的所有映像后返回不同的映像。图像的计数恢复得很好,所以我知道它们正在被拾取。

我遇到的问题是,我似乎无法将项目的源代码放入数组,然后在"Do Stuff"块中检查和操作它。他们都是空荡荡的。我也尝试过用this.src代替this.getAttribute("src");,但似乎也不起作用。我很确定,在这种情况下,这是因为"this"指的是类,而不是属于类的图像,我对此是否正确?如果是这样的话,如何获得图像源?

var images = []; //Create the image array
//Get the images on this page, add them to the array
$(".image-to-be-reloaded").each(function (i) {
    images[i] = this.getAttribute("src");
    console.log(images[i]);
});
var number = images.length; //Used to check the number of image items is correct
//Check that all images on the page have already loaded
load_counter = 0; //Reset start values
$(images).each(function (i, item) {
    $(item).load(function () {
        load_counter++;
        if (load_counter === images.length) {
            //All items have loaded - Do stuff!
            alert("Whehey!");
            images[i] = "imagenumber" + i;
        }
    })
});

只需使用每个的第二个参数:

each(function (i,ele) {
    ele.getAttribute("src");
...

或查看文档:http://api.jquery.com/each/

最新更新