0

好吧,这没有任何意义,而且太可笑了,我就是不明白。

所以,我有一个功能来制作图片。

function mk_image(src, alt, title, link) {
       img = new Image();
        img.src = src;
        img.id='ShowC_Img_'+count_image;
        count_image+=1;
        img.width = 960;
        img.height = 320;
        img.alt = alt;
        img.style.display='none';
        img.setAttribute('border',"0");
        return [img,'url('+src+')',link];
    }

然后我以这种方式制作 13 个元素的数组,例如:

var items = [/* mk_image('image_source', 'alt', 'title', 'link'), etc... */

然后我遍历数组并进行以下操作:

for (i=0; i<items.length;i++){
              $(items[i][0]).one('load', function(){ 
//blablabla
}).each(function(){
                if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) 
                $(this).trigger("load");})
            .error(function(){alert('shit');}); 
        }

然后你猜怎么着。有时它会在 IE 中触发 8 张图片,-有时......所有这些,我只是不明白............虽然在谷歌浏览器中工作 100% 完美。

有任何想法吗?

4

1 回答 1

2

好的,因为它看起来有点大,尝试使用以下来更详细地调试(一次直接设置 src 属性,一次不设置):

function mk_image(src, alt, title, link) {
    img = new Image();
    img.src = src;
    img.id='ShowC_Img_'+count_image;
    count_image+=1;
    img.width = 960;
    img.height = 320;
    img.alt = alt;
    img.style.display='none';
    img.setAttribute('border',"0");
    return [img,'url('+src+')',link];
}

var items = [/* mk_image('image_source', 'alt', 'title', 'link'), etc... */

function onLoad(img) {
  console.log(img || this); // check this output (are all images displayed?)
}

for (i=0; i<items.length;i++){
  $(items[i][0]).one("load", onLoad)
  .each(function(){
    if (this.complete || this.readyState === 4 || this.readyState === "complete") {
      onLoad(this);
    }
  })
  .error(function(){alert('shit');}); 
}
于 2012-04-30T16:31:39.787 回答