settimeout issue in IE8

后端 未结 2 759
轻奢々
轻奢々 2021-01-20 15:58

I am facing a strange issue while using javascript setTimeout function in IE8. I want to use the \'setTimeout\' function like this -

setTimeout(timeout,2000         


        
2条回答
  •  清歌不尽
    2021-01-20 16:23

    If you want to call timeout with changing variable (e.g. calling timeout in loop with lot of names) you can use also in IE8:

    var names = ["saarthak", "saarthak2", "saarthak3"]; 
    for (var q in names) {
      setTimeout(
        (function(opts){
              return function(){
                        alert ("hello " + opts.name)            
                      }
         })({name:names[q]}), 2000);
    }
    

    see: http://jsfiddle.net/q4HYz/

提交回复
热议问题