jQuery:在widget中延迟事件调用

时间:2011-06-26 12:39:41

标签: jquery event-handling delay

我无法找到如何延迟窗口小部件的事件处理程序。 我像这样绑定事件:

enable: function () {
    this.options.isEnabled = true;
    this.element.bind("keyup", $.proxy(this, "_populateList"));
},

我想延迟调用“_populateList”。但我使用setTimeout的尝试无效。

“_populateList”:

_populateList: function (event) {
    var that = this;
    // do my stuffs
}

由于

1 个答案:

答案 0 :(得分:1)

试试这个:

enable: function () {
    this.options.isEnabled = true;
    var that = this;
    this.element.bind("keyup", function(event){
       $(this)
          .delay(1000) // delayed time in milliseconds
          .queue(function(next){
             that._populateList(event);
             next();
          });
    });
},
相关问题