简体   繁体   English

setTimeout作为IE8及更低版本中的对象

[英]setTimeout as object in IE8 and lower

I'm sorry I have to ask for this, because there are many similar questions here, but I can't find a solution of my problem. 很抱歉,我必须要这个,因为这里有很多类似的问题,但是我找不到解决问题的方法。 I use setTimeout and it works in alle browsers, chrome, ff and also in IE9 and higher. 我使用setTimeout,它可以在alle浏览器,chrome,ff和IE9及更高版本中使用。 But in IE8 the things that should execute after the timeout do not work. 但是在IE8中,超时后应执行的操作不起作用。 I hope someboday can help me with it... 我希望有一天可以帮助我...

var searching = {
    initialize: function (config) {
        this.wait(config.time);
    },
    wait: function(time) {
        setTimeout(function(){      
            $("#example-div").hide;
        }, time);
    }
}
$("#example-submit").click(function() {
    searching.initialize({time: 4000});
}

Reason: There is an error in your script, and other browsers continue the script execution when the error is in a setTimeout / setInterval 原因:您的脚本中有错误,并且当错误位于setTimeout / setInterval中时,其他浏览器会继续执行脚本

In case of IE this does not happen. 如果是IE,则不会发生。

So either you should fix your code, or wrap your code in try{...}catch(e){...} blocks. 因此,您应该修复代码,或将代码包装在try{...}catch(e){...}块中。

The code is almost right. 该代码几乎是正确的。 You're missing some paranthesis: 您缺少一些特效:

HTML: HTML:

<div id="example-div">example-div</div>
<div id="example-submit">example-submit</div>

JS: JS:

var searching = {
    initialize: function (config) {
        this.wait(config.time);
    },
    wait: function(time) {
        setTimeout(function(){      
            $("#example-div").hide();
        }, time);
    }
}
$("#example-submit").click(function() {
    searching.initialize({time: 4000});
});

Fiddle: http://jsfiddle.net/t6NEQ/2/ 小提琴: http//jsfiddle.net/t6NEQ/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM