【发布时间】:2014-10-20 14:13:52
【问题描述】:
我正在尝试创建一个服务器控件,该控件在加载某个类的所有图像后返回不同的图像。对图像的计数恢复正常,所以我知道它们正在被拾取。
我遇到的问题是我似乎无法将项目的源放入数组中,然后在“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;
}
})
});
【问题讨论】:
标签: c# jquery asp.net webforms