Highlight jQuery UI autocomplete

后端 未结 3 1472
醉梦人生
醉梦人生 2020-12-29 07:53

I\'m using the autocomplete function in jQuery UI 1.8.6. And I want to highlight matching results. But for some reason when I use a regex to add \"strong\" tags around the m

3条回答
  •  自闭症患者
    2020-12-29 08:35

    $.extend($.ui.autocomplete.prototype, {
        _renderItem: function (ul, item) {
            var searchMask = this.element.val();
            var regEx = new RegExp(searchMask, "ig");
            var replaceMask = "$&";
            var html = item.label.replace(regEx, replaceMask);
    
            return $("
  • ") .data("item.autocomplete", item) .append($("").html(html)) .appendTo(ul); } });

提交回复
热议问题