How to make matched text bold with jquery ui autocomplete?

后端 未结 5 1381
南旧
南旧 2020-12-08 05:04

I am wondering how to make the matched part of the autocomplete suggestions bold when using jquery ui autocomplete?

So for example if you type in \"ja\" and the sugg

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 05:29

    In jQuery UI 1.11.1, 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.text(me.text().replace(new RegExp("(" + keywords + ")", "gi"), '$1'));
         });
     }
    

提交回复
热议问题