码迷,mamicode.com
首页 > 其他好文 > 详细

input autocomplete 下拉提示+支持中文

时间:2015-05-19 14:26:27      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

js 代码:

$.getJSON("/Foreign/Getforeign_routeEndPoint", function (data) {
            $("#NameReturn_Arch").autocomplete(data, {
                minChars: 0, //表示在自动完成激活之前填入的最小字符
                max: 100, //表示列表里的条目数
                autoFill: true, //表示自动填充
                mustMatch: true, //表示必须匹配条目,文本框里输入的内容,必须是data参数里的数据,如果不匹配,文本框就被清空
                matchContains: false, //表示包含匹配,相当于模糊匹配
                scrollHeight: 200, //表示列表显示高度,默认高度为180
                dataType: "json", //数据格式      

                formatItem: function (row) {
                    return row.text;
                },
                formatMatch: function (row) {
                    return row.text;
                },
                formatResult: function (row) {
                    return row.text;
                }
            });
        });

 

后台:

    public ActionResult Getforeign_routeEndPoint()
        {
            List<foreign_route> List = for_rou.GetRouteCodeName("EndPoint").ToList();
            List<SelectText> ulist = new List<SelectText>();
            if (List.Count > 0)
            {
                string[] endPoint;
                SelectText text;
                foreach (var i in List)
                {
                    endPoint = i.EndPoint.Split(‘、‘);
                    if (endPoint.Length > 1)
                    {
                        foreach (string t in endPoint)
                        {
                            text = new SelectText { id = t, text = t };
                            if (!ulist.Any(x=>x.id==t&&x.text==t))
                            {
                                ulist.Add(text);
                            }
                        }
                    }
                    else
                    {
                        text = new SelectText { id = i.EndPoint, text = i.EndPoint };
                        if (!!ulist.Any(x => x.id == i.EndPoint && x.text == i.EndPoint))
                        {
                            ulist.Add(text);
                        }
                    }
                }
            }

            return Json(ulist, JsonRequestBehavior.AllowGet);
        }

 

由于有的浏览器不兼容,所以需要修改一下jquery.autocomplete.js代码

在js脚本里面的199行或者200行添加修改

.bind("input", function() {  
            onChange(0, true);  
        }).bind("unautocomplete", function() {
        select.unbind();
        $input.unbind();
        $(input.form).unbind(".autocomplete");
    });
   

input autocomplete 下拉提示+支持中文

标签:

原文地址:http://www.cnblogs.com/zh1989/p/4514466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!