0

我认为这很容易,但似乎我要么做空要么做多。

我试图让它在 3 分钟后退出用户这是倒计时我认为可以工作我尝试了 3000、300、3*60、3*1000 等等

var timeout = 30*1800;

这是我要运行的功能,

    function loadidle(){

          var timeout = 180000;
          //alert(timeout);

          $(document).bind("idle.idleTimer", function(){

              logout();

          });


          $.idleTimer(timeout);
}
4

2 回答 2

1

很确定 JS(以及因此 jQuery)使用毫秒,所以你会想要 3*60*1000。

于 2011-09-12T00:21:28.400 回答
1

你只需要一个简单的计时器。有很多品种。这是一个非常便宜的示例,它很好地将其抽象为一个类。您可以通过调用 .reset() 来“继续”计时器。

function Timeout(seconds, callback){
    this.length = seconds * 1000;
    this.callback = callback;
    this.start();
}
Timeout.prototype = {
    start: function(){
        var self = this;
        this.stop();
        this.timer = setTimeout(function(){
            self.complete();
        },this.length);
    },
    stop: function(){
        if (this.timer) clearTimeout(this.timer);
        this.timer = null;
    },
    complete: function(){
        if (this.callback) this.callback();
        this.stop();
    },
    reset: function() {
        this.stop();
        this.start();
    }
}

开始一个新的计时器:

var timer = new Timeout(3 * 60, logout);
timer.reset(); // refresh the timer
timer.stop(); // cancel the timer
于 2011-09-12T01:41:11.683 回答