我有这个疯狂的JavaScript问题与IE7和IE8。下面的函数表达式加载一些图像。而已。非常简单。当函数被直接调用,即testmypatience()
它会像它应该那样工作,但如果我从超时内调用它,它将不会加载图像。该函数被调用,但图像不会加载。当由jQuery animate回调调用时,它也无法工作。功能不工作,因为它应该在IE7和IE8从setTimeout调用
我试过了一切,我无法得到它的工作,所以你的帮助将是最感激。
var testmypatience = function($active){
var arr = ['images/site/products-medium/m_cordial_pomegranateelderflower.png', 'images/site/products-medium/m_cordial_spicedberry.png', 'images/site/products-medium/m_cordial_strawberryelderflower.png', 'images/site/products-medium/m_750presse_coxsapple.png', 'images/site/products-medium/m_party_appleandelderflower.png', 'images/site/products-medium/m_squeezy_blackcurrentandapple.png', 'images/site/products-medium/m_270presse_cranberryandorange.png', 'images/site/products-medium/m_270presse_elderflower.png', 'images/site/products-medium/m_270presse_gingerlemongrass.png'];
for (i = 0; i < arr.length; i++) {
var img, len;
img = new Image();
img.src = arr[i];
img.onload = function(){
console.log('done ' + this.src);
}
}
}
//this works
testmypatience()
//None of these work
setTimeout(function(){
testmypatience()
}, 400)
setTimeout(testmypatience, 400)
jQuery('elm').animate({left:'1000px'},
{
duration:200,
complete: testmypatience
});
我只是想补充一点,当我说“没有这些工作,”上面我的意思是他们做调用函数但IE7和IE8不会触发onload事件,也不会加载图像。 – screenm0nkey 2011-03-02 11:41:48
也许你必须把1000px放在''''内。如果需要,请在Chrome中运行。 – pimvdb 2011-03-02 11:42:16
@pimvdb - 这只是一个例子。我只是表明它是从Jquery方法中调用的。从回调中调用它不起作用的地步。我会从代码中删除这一点,因为它很明显造成混乱 – screenm0nkey 2011-03-02 11:57:11