Debounce function in jQuery

后端 未结 1 1410
终归单人心
终归单人心 2020-11-30 09:40

I\'m attempting to debounce a button\'s input using the jquery debouncing library by Ben Alman. http://benalman.com/code/projects/jquery-throttle-debounce/examples/debounce/

相关标签:
1条回答
  • 2020-11-30 10:27

    I ran into the same issue. The problem is happening because the debounce function returns a new function which isn't being called anywhere.

    To fix this, you will have to pass in the debouncing function as a parameter to the jquery click event. Here is the code that you should have.

    $(".my-btn").click($.debounce(250, function(e) {
        console.log("It works!");
    }));
    
    0 讨论(0)
提交回复
热议问题