• Jquery实现自动提示下拉框


    1、引入脚本库:
        <script type="text/javascript" src="/Jscripts/jquery-1.3.2.js"></script>

        <script src="/Jscripts/jquery.autocomplete.js" type="text/javascript"></script>
       

    2、在Demo.aspx页面中加入如下脚本:
            $(document).ready(function() {
                $.ajax({
                    type: "POST",
                    contentType: "application/json",
                    url: "Demo.aspx/GetDataBind",
                    data: "{}",
                    dataType: "json",
                    success: function(msg) {
                        var datas = eval_r('(' + msg.d + ')');
                        $("#txtName").autocomplete(datas, {
                            max: 12,
                            minChars: 0,
                            140,
                            scrollHeight: 300,
                            matchContains: true,
                            autoFill: false, //自动填充
                            formatItem: function(row, i, max, value) {
                                return row.Key;
                            },
                            formatMatch: function(row, i, max, value) {
                                return row.Key;
                            },
                            formatResult: function(row) {
                                return row.Key;
                            }
                        }).result(function(event, row, formatted) {
                            $("#hidID").val(row.Value);
                        });
                    }
                });
            });
    3、页面中需要提供txtName、hidID控件:
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
      
        <asp:HiddenField ID="hidID" runat="server" />
       

    4、Demo.aspx.cs后台代码:

            [WebMethod]
            public static string GetDataBind()
            {
                Dictionary data = new Dictionary();

                IList userinfos = GetByName();
                if (userinfos != null)
                {
                    foreach (Employee e in userinfos)
                    {
                        data.Add(e.cName + "-" + e.eName, e.Empno);
                    }
                }
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(data.GetType());
                using (MemoryStream ms = new MemoryStream())
                {
                    serializer.WriteObject(ms, data);
                    return System.Text.Encoding.UTF8.GetString(ms.ToArray());
                }
            }

  • 相关阅读:
    sql FLOAT字段使用like查询
    关于sql--时间范围查询重叠
    关于java时间类型比较
    前端-搜索无结果时,怎么把“暂无数据“显示出来?
    v-for动态赋值给不同的下拉框input
    Java的优先队列PriorityQueue详解
    软件体系架构阅读笔记八
    字符数组和字符串之间的转换
    Java快速输入输出
    软件体系架构阅读笔记七
  • 原文地址:https://www.cnblogs.com/yumianhu/p/3710732.html
Copyright © 2020-2023  润新知