开发者

Speeding up jQuery Autocomplete initialization

开发者 https://www.devze.com 2023-03-12 03:55 出处:网络
I\'m using multiple (100+) autocomplete fields on the same page, all with the same data source, and have noticed that the initialization of the autocomplete fields is a bit slow. From some profiling I

I'm using multiple (100+) autocomplete fields on the same page, all with the same data source, and have noticed that the initialization of the autocomplete fields is a bit slow. From some profiling I've done it looks like the bottleneck is the creation of the menu (this.menu = $( "<ul></ul>" ) and so forth in the source code).

It seems kind of unnecessary to create separate menues for each aut开发者_开发问答ocomplete field, and so I was wondering if someone knows of a way to make this initialization faster.

I was thinking of making jQuery UI just use the same menu (or preferably the same autocomplete object) on all the input fields, but I don't know how this could be done without modifying the plugin source code.


You can try only initializing the autocomplete field when the user clicks the field


I had the same problem and fixed it by initialise auto-complete on focus:

$(".complete").focus(function(){

    $(this).autocomplete({
        //your options  
    });

});

The field with auto-complete function needs the class "complete" off course.

0

精彩评论

暂无评论...
验证码 换一张
取 消