定时器传参数

定时器
setTimeout() 和 setInterval() 在使用函数名作为调用句柄是都不能带参数,因此定义一个函数_checkMsg(),返回一个不带参数的函数,在
这个函数内部调用外部函数checkMsg(),不需使用参数。
setInterval(_checkMsg(isLogin),1000);
 
function checkMsg(uid){
       $.ajax
          ({
               type: "post",
               url: "ajax_process.php?action=unread",
               dataType: "json",
               data: {"isLogin":uid},
               success: function(json)
               {
                 if(json.success == 1)
                   {
                      $('#new_message').fadeIn();
                   }else
                   {
                        $('#new_message').fadeOut();
                    }
               }
            });
     }
 
     function _checkMsg(uid){
        return function(){
          checkMsg(uid);
        }
     }

posted on 2016-01-26 13:59  迷茫小飞侠  阅读(724)  评论(0编辑  收藏  举报

导航