How to highlight input words in autocomplete jquery ui

后端 未结 6 2185
后悔当初
后悔当初 2020-12-25 13:46

Could you please help me in highlighting the typed words in the auto complete text box. i am already populating the autocomplete words and i need to just highlight the typed

6条回答
  •  死守一世寂寞
    2020-12-25 14:15

    Here is the code I used to make it work (case insensitive):

    open: function (e, ui) {
          var acData = $(this).data('ui-autocomplete');
          acData.menu.element.find('li').each(function () {
             var me = $(this);
             var keywords = acData.term.split(' ').join('|');
             me.html(me.text().replace(new RegExp("(" + keywords + ")", "gi"), '$1'));
          });
       }
    

提交回复
热议问题