如何延遲.keyup()處理函數,直到用戶中止鍵入? - How to delay the .keyup() handler until the user stops typing?

問題:

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
相關文章
相關標籤/搜索