问题:
I've got a search field. 我有一个搜索字段。 Right now it searches for every keyup. 现在,它会搜索每个键。 So if someone types “Windows”, it will make a search with AJAX for every keyup: “W”, “Wi”, “Win”, “Wind”, “Windo”, “Window”, “Windows”. 因此,如果有人键入“ Windows”,它将使用AJAX搜索每个键入的内容:“ W”,“ Wi”,“ Win”,“ Wind”,“ Windo”,“ Window”,“ Windows”。
I want to have a delay, so it only searches when the user stops typing for 200 ms. 我希望有一个延迟,因此它仅在用户停止键入200毫秒时才搜索。
There is no option for this in the keyup
function, and I have tried setTimeout
, but it didn't work. 在keyup
函数中没有用于此的选项,我已经尝试过setTimeout
,但是它没有用。
How can I do that? 我怎样才能做到这一点?
解决方案:
参考一: https://stackoom.com/question/80jR/如何延迟-keyup-处理函数-直到用户停止键入参考二: https://oldbug.net/q/80jR/How-to-delay-the-keyup-handler-until-the-user-stops-typing
来源:oschina
链接:https://my.oschina.net/u/4428122/blog/4373756