开发者

problem with setTimeout "function is not define" !

problem with setTimeout "function is not define" !

What is the problem in this code ?

$(document).ready(function(){ 

 function ISS_NextImage() { //ImageSlideShow NextImage
  $('.ImageSl开发者_如何学JAVAideShow').each(function() {
   alert($(".correntImage", this).text());
  });
 }

 var t=setTimeout("ISS_NextImage();",1000);

});


When you eval code, it is done in the global scope. Since the function you are trying to call is locally scoped, this fails.

Pass the function to setTimeout instead of passing a string to be evaled.

var t=setTimeout(ISS_NextImage,1000);


Try changing your set timeout call to this:

var t=setTimeout(function(){ISS_NextImage();},1000);


Avoid passing a string to setTimeout(). Just pass a reference to the function instead:

var t = setTimeout(IIS_NextImage, 1000);


you could also:

$(function() { 
    var t = setTimeout(new function() {
       $('.ImageSlideShow').each(function() {
           alert($(".correntImage", this).text());
       });
    }, 1000);
});


You could do something like this:

$(document).ready(function(){ 
    setTimeout(ISS_NextImage,1000);
});

function ISS_NextImage() { 
    $('.ImageSlideShow').each(function() {
      alert($(".correntImage", this).text());
    });
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜