好吧,这没有任何意义,太可笑了,我就是不明白。
所以,我有一个制作图片的功能。
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% 完美。
有什么想法吗?
最佳答案
好吧,因为它看起来有点大,尝试使用以下内容来更详细地调试(一次直接设置 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');});
}
关于javascript - Img one ('load' , ...) 并不总是在 IE 中触发 - 我放弃了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10386884/