亮点的话jQuery用户界面如何自动完成 [英] How highlight words jquery ui autocomplete

查看:99
本文介绍了亮点的话jQuery用户界面如何自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个脚本 http://jqueryui.com/demos/autocomplete/#default 与数据库。我想强调类型化的话是这样的:www.docs.jquery.com/Plugins/Autocomplete。请帮我。

i'm using this script http://jqueryui.com/demos/autocomplete/#default with database. i want to highlight typed words like this: www.docs.jquery.com/Plugins/Autocomplete. Please help me.

推荐答案

我必须按照这个的突出jQuery用户界面自动完成,使其工作

I had to modify the code according to this Highlight jQuery UI autocomplete to make it work

        $("#searchBox").autocomplete({
        source: function(request, response) {
            $.ajax({
                url: "search.php",
                dataType: "json",
                data: request,
                success: function( data ) {
                    var escapedTerm=request.term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1");
                    var regex = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + escapedTerm + ")(?![^<>]*>)(?![^&;]+;)", "gi");
                    var result = $.map(data, function(value){
                        //console.log(value);
                        value.label=value.label.replace(regex, "<span class='highlight'>$1</span>");
                        return value;
                    });
                    response(result);
                }
            });
        },
        minLength: 3
    })
    .data('autocomplete')._renderItem = function( ul, item ) {
        return $( "<li></li>" )
            .data( "item.autocomplete", item )
            .append( '<a>' + item.label + '</a>' )
            .appendTo( ul );
    };

这篇关于亮点的话jQuery用户界面如何自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆