setInterval 这个函数,怎么在传入function 的时候写参数呢?

代码如下:
这里用了setInterval一个time_count 函数, 但是里面还有参数StrRand , firstTime,怎么传呢?
这个 time_count 在别的地方还有用,不能写setInterval里.

setInterval( time_count ,2000);



function time_count(StrRand , firstTime)
{
    $.ajax
        (
            {
                type : 'POST',      //默认是GET
                url : '/egg/api.php/home/api/count_live',
                data:{ 'time': firstTime , 'StrRand' : StrRand , 'shop_id' : shop_id },

                success : function (data)    //成功函数,data 就是从*.php echo 的字符串内容;
                {
                    //console.log( data );
                    console.log( StrRand );
                },
                cache:false    //是否使用缓存
            }
        );
}
阅读 12.1k
4 个回答
// 方法一
setInterval(time_count, 2000, StrRand, firstTime)

// 方法二
setInterval(() => {
    time_count(StrRand, firstTime)
}, 2000)

传递多个参数

function qaq(name){
    console.log(name);
}
setInterval(qaq,1000,["qaq","aqq"]);

传递一个参数

setInterval(qaq,1000,"qaq");

setInterval(function(){ //your code }, 2000)

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题