问题:
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毫秒时才搜索。 this
There is no option for this in the keyup
function, and I have tried setTimeout
, but it didn't work. 在keyup
函数中没有用于此的选项,我已经尝试过setTimeout
,可是它没有用。 spa
How can I do that? 我怎样才能作到这一点? .net
解决方案:
参考一: https://stackoom.com/question/80jR/如何延迟-keyup-处理函数-直到用户中止键入参考二: https://oldbug.net/q/80jR/How-to-delay-the-keyup-handler-until-the-user-stops-typing