Skip to content

Jquery 重复监听

ythy edited this page Sep 1, 2017 · 1 revision
setPagerListenerAndPlugins(pagerData:LBSearchStoreListResultInfo):void{
    $(document).on('click', '#lastPage', null, ():void=>{
      this.onSearch(pagerData.startIndex - this.mPageSize);
    });
}

上述方法setPagerListenerAndPlugins执行多次后, 每次Click都会触发监听及onSearch多次.

正确做法是先清除监听:

setPagerListenerAndPlugins(pagerData:LBSearchStoreListResultInfo):void{
    $(document).off('click', '#lastPage');
    $(document).on('click', '#lastPage', null, ():void=>{
      this.onSearch(pagerData.startIndex - this.mPageSize);
    });
}
Clone this wiki locally