【问题标题】:Getting Custom Server Control src into a jQuery array once images are loaded加载图像后,将自定义服务器控件 src 放入 jQuery 数组
【发布时间】: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


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2018-12-17
      • 2010-12-24
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 2011-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多