Javascript 函数不';在IE7&;从setTimeout调用时的IE8

Javascript 函数不';在IE7&;从setTimeout调用时的IE8,javascript,jquery,Javascript,Jquery,我在IE7和IE8上遇到了一个疯狂的javascript问题。下面的函数表达式加载一些图像。就这样。很简单。当直接调用函数ietestmypatience()时,它会正常工作,但如果我在超时时间内调用它,它将不会加载图像。已调用该函数,但不会加载图像。当jQuery animate回调调用时,它也无法工作 我已经试过了所有的方法,但都不能成功,所以非常感谢你的帮助 var testmypatience = function($active){ var arr =

我在IE7和IE8上遇到了一个疯狂的javascript问题。下面的函数表达式加载一些图像。就这样。很简单。当直接调用函数ie
testmypatience()
时,它会正常工作,但如果我在超时时间内调用它,它将不会加载图像。已调用该函数,但不会加载图像。当jQuery animate回调调用时,它也无法工作

我已经试过了所有的方法,但都不能成功,所以非常感谢你的帮助

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
    });
var testmypatience=函数($active){
var arr=['images/site/products medium/m_cordial_石榴花儿.png','images/site/products medium/m_cordial_spicedberry.png','images/site/products medium/m_750; presse_coxsapple.png','images/site/products medium/m_party_applederflower.png','images/site/products medium/m_applederflower.png','zy_blackcurrentandapple.png”、“images/site/products medium/m_270 presse_cranberry and range.png”、“images/site/products medium/m_270 presse_elderflower.png”、“images/site/products medium/m_270 presse_gingerlemongrass.png];
对于(i=0;i
IE7和IE8没有控制台,除非为此安装了浏览器扩展/插件。请使用
控制台注释行。记录调用或使用类似


正如pimvdb所说,
1000px
应该用引号括起来(没有引号,它在所有浏览器中都会中断,这是无效的javascript语法)。

IE7和IE8没有控制台,除非为此安装了浏览器扩展/插件。请使用
控制台注释行。记录
调用或使用类似的方法


同样正如pimvdb所说,
1000px
应该加引号(如果没有引号,它在所有浏览器中都会中断,这是无效的javascript语法).

我已经对它进行了排序。我必须先在dom中插入一个空图像对象,然后给它一个src属性,然后它才会在IE7和IE8中触发onload事件。如果我有点含糊不清,请随时提问,我会回答您的所有问题

$(function(){
                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).prependTo('body');

                        img.onload = function(){
                            console.log('done ' + this.src);
                        }
                    }

                    $('img').each(function(i, elm){
                        elm.src = arr[i];
                    })
                }

                setTimeout(function(){
                    testmypatience()
                }, 400)
            })
$(函数(){
var testmypatience=函数($active){
var arr=['images/site/products medium/m_cordial_石榴花儿.png','images/site/products medium/m_cordial_spicedberry.png','images/site/products medium/m_750; presse_coxsapple.png','images/site/products medium/m_party_applederflower.png','images/site/products medium/m_applederflower.png','zy_blackcurrentandapple.png”、“images/site/products medium/m_270 presse_cranberry and range.png”、“images/site/products medium/m_270 presse_elderflower.png”、“images/site/products medium/m_270 presse_gingerlemongrass.png];
对于(i=0;i
我已经对它进行了排序。我必须先在dom中插入一个空图像对象,然后给它一个src属性,然后它才会在IE7和IE8中触发onload事件。如果我有点含糊不清,请随时提问,我会回答您的所有问题

$(function(){
                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).prependTo('body');

                        img.onload = function(){
                            console.log('done ' + this.src);
                        }
                    }

                    $('img').each(function(i, elm){
                        elm.src = arr[i];
                    })
                }

                setTimeout(function(){
                    testmypatience()
                }, 400)
            })
$(函数(){
var testmypatience=函数($active){
var arr=['images/site/products medium/m_cordial_石榴花儿.png','images/site/products medium/m_cordial_spicedberry.png','images/site/products medium/m_750; presse_coxsapple.png','images/site/products medium/m_party_applederflower.png','images/site/products medium/m_applederflower.png','zy_blackcurrentandapple.png”、“images/site/products medium/m_270 presse_cranberry and range.png”、“images/site/products medium/m_270 presse_elderflower.png”、“images/site/products medium/m_270 presse_gingerlemongrass.png];
对于(i=0;i
您不需要像解决方案中那样复杂。只需交换
src
onload
的赋值即可

错误:

img = new Image();
img.src = arr[i];
img.onload = function(){ ... }
img = new Image();
img.onload = function(){ ... }
img.src = arr[i];
右侧:

img = new Image();
img.src = arr[i];
img.onload = function(){ ... }
img = new Image();
img.onload = function(){ ... }
img.src = arr[i];

您不需要像解决方案中那样复杂。只需交换
src
onload
的赋值即可

错误:

img = new Image();
img.src = arr[i];
img.onload = function(){ ... }
img = new Image();
img.onload = function(){ ... }
img.src = arr[i];
右侧:

img = new Image();
img.src = arr[i];
img.onload = function(){ ... }
img = new Image();
img.onload = function(){ ... }
img.src = arr[i];
我只想喝一杯