Efficient AutoSuggest with jQuery?

前端 未结 4 1621
北荒
北荒 2021-02-01 11:15

I\'m working to build a jQuery AutoSuggest plugin, inspired by Apple\'s spotlight.

Here is the general code:

$(document).ready(function() { 
$(\'#q\').         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 12:02

    I'd go for a variant of C. Don't wait for users to stop typing, but wait some time (200ms?) after the first keystroke. Then after that time, you will in many cases have received additional keystrokes and then you use the typed characters to get the autosuggest. If another key is pressed after submitting the request, you start counting again.

    And you should definitely do some caching too; people will use backspace and you'll have to show the name list again.

提交回复
热议问题