Throttle event calls in jQuery

前端 未结 7 871
自闭症患者
自闭症患者 2020-11-27 03:52

I have a keyup event bound to a function that takes about a quarter of a second to complete.

$(\"#search\").keyup(function() {
  //code that tak         


        
7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 04:14

    Take a look at jQuery Debounce.

    $('#search').keyup($.debounce(function() {
        // Will only execute 300ms after the last keypress.
    }, 300));
    

提交回复
热议问题