Run javascript function when user finishes typing instead of on key up?

前端 未结 29 2482
我寻月下人不归
我寻月下人不归 2020-11-22 04:03

I want to trigger an ajax request when the user has finished typing in a text box. I don\'t want it to run the function on every time the user types a letter because that wo

29条回答
  •  执笔经年
    2020-11-22 04:46

    Well, strictly speaking no, as the computer cannot guess when the user has finished typing. You could of course fire a timer on key up, and reset it on every subsequent key up. If the timer expires, the user hasn't typed for the timer duration - you could call that "finished typing".

    If you expect users to make pauses while typing, there's no way to know when they are done.

    (Unless of course you can tell from the data when they are done)

提交回复
热议问题