2014-01-16 29 views
0

我有这个功能,并且我试图在它再次运行时将wordtype字符串变量传递回相同的函数。在自引用函数中传递字符串变量

现在,除了第一次运行(当我实际送入字符串时) - 它显示为undefined为wordtype。我这样称呼它:rotateWordsA('nouns');

我该如何让rotateWordsA(wordtype);实际上将字符串传回给下一轮动画?

i=0; 
    function rotateWordsA(wordtype){ 
     console.log(wordtype); 
     var xyz = "#"+wordtype+" div."+i; 
     //console.log(xyz); 

     $("#"+wordtype+" div."+i).fadeOut(1000).hide(); 
     //alert('hi'); 
     i++; 
     //alert(i); 
     if($("#"+wordtype+" div."+i).length){ 
      prev = i-1; 
      $("#"+wordtype+" div."+prev).fadeOut(1000).hide("slow"); 
      $("#"+wordtype+" div."+i).fadeIn(1000).show(); 
      $("#"+wordtype+" div."+i).delay(1000).animate({ 
           //display: "show", 
           //left: "+=500", 
           opacity: 1 
           }, 1000, function(){ 
           setTimeout(function(){rotateWordsA()}, 2500) 

           }); 

         } 
         else{ 

          i=0; 
          rotateWordsA(wordtype); 
         } 
    } 

回答

3

你是不是传递变量的setTimeout

​​
+0

是以函数调用。谢谢你加入snark。只要我问了这个问题,我就注意到了未通过的变量。谢谢@Satpal! – itamar

相关问题