Limit the result in jQuery Autocomplete

前端 未结 5 1537
情书的邮戳
情书的邮戳 2021-01-04 18:45

How can you set a limit on the result from the jQuery autocomplete?

This is my code:

        $.ajax({
            url: \"/cache/search/SearchModels.x         


        
5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-04 19:22

    You could add a handler for the "open" event:

        open:function(event,ui){ 
        var maxListLength=10;
        var ul = jQuery( "#txtTopSearch" ).autocomplete("widget")[0];
        while(ul.childNodes.length > maxListLength)
              ul.removeChild(ul.childNodes[ul.childNodes.length-1]);
        }
    

提交回复
热议问题