How to pass parameter to an anonymous function defined in the setTimeout call?

后端 未结 2 1876
夕颜
夕颜 2021-01-22 21:38

Here is my code:

function addRcd2(timeOut){  
  for(var c=0; c less 5; c++){
    var rcdi = \"rcd_\"+c+\"\";
    setTimeout(function(){
      $(\'.tbl1 tbody\').appen         


        
2条回答
  •  -上瘾入骨i
    2021-01-22 22:08

    function addRcd2(timeOut){  
      for(var c=0; c less 5; c++){
        var rcdi = "rcd_"+c+"";
        setTimeout((function(x) {
          return function(){
            $('.tbl1 tbody').append(x);
          };
        })(rcdi),timeOut*c);
      }
    }
    

提交回复
热议问题