How to trigger an onkeyup event that's delayed until a user pauses their typing?

后端 未结 7 746
生来不讨喜
生来不讨喜 2020-11-29 03:16

I have a textarea where people enter some text (naturally), and I want to make it so that an AJAX request is made every now and then to get some suggestions regarding what t

7条回答
  •  庸人自扰
    2020-11-29 04:01

    If you are using lodash.js (or underscore.js) you can use the debounce function.

    Example (jQuery used for keyup):

    $('#myTextArea').keyup(_.debounce(function() {
      alert('hello');
    }, 500));
    

提交回复
热议问题