How to make matched text bold with jquery ui autocomplete?

后端 未结 5 1367
南旧
南旧 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:37

    Here's a solution for those who want to search case insensitive (only the open function is diffirent):

            open: function(e,ui) {
                var
                acData = $(this).data('autocomplete');
    
                acData
                .menu
                .element
                .find('a')
                .each(function() {
                    var me = $(this);
                    var regex = new RegExp(acData.term, "gi");
                    me.html( me.text().replace(regex, function (matched) {
                        return termTemplate.replace('%s', matched);
                    }) );
                });
            }
    

提交回复
热议问题