0

在下面的代码中,我需要立即执行带有 debounce(延迟)的 show_error 方法和 show_value 方法。

这两种方法只需要在停止事件中怎么做?

$("#test").spinner({
 stop: function(event , ui){
 show_value();
  },
 stop: _.debounce(function(e, ui) {
      show_error();

    }, 300)
        });
4

1 回答 1

0

在单个处理程序中调用这两个函数:

var debouncedStop = _.debounce(function(e, ui) {
      show_error();
}, 300);
$("#test").spinner({
 stop: function(event, ui){
     show_value();
     debouncedStop();
 }
});

或者分别绑定它们:

$("#test").spinner()
          .on("spinstop", function(event , ui) {
              show_value();
          })
          .on("spinstop", _.debounce(function(e, ui) {
              show_error();
          }, 300));
于 2016-10-18T11:35:48.083 回答