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. But in IE8 the things that should execute after the timeout do not work. 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
In case of IE this does not happen.
So either you should fix your code, or wrap your code in try{...}catch(e){...}
blocks.
The code is almost right. You're missing some paranthesis:
HTML:
<div id="example-div">example-div</div>
<div id="example-submit">example-submit</div>
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/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.