zoukankan      html  css  js  c++  java
  • jQuery插件之AutoComplete使用方法

    https://files.cnblogs.com/jianjialin/jquery.autocomplete.js
    https://files.cnblogs.com/jianjialin/jquery.autocomplete.css
    public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            context.Response.Write(getProducts(context));
        }
        private string getProducts(HttpContext context)
        {
            string sql = "select * from products";
            string re = JsonHelper.ConvertDataTableToJson(SqlHelper.ExecuteDataSet(sql).Tables[0]);
            return re;
        }

        <script type="text/javascript">
            /*==========用户自定义方法==========*/
            //城市数据
            var cityList;
            //autocomplete选项
            var options = {
                minChars: 1,
                max: 500,
                 250,
                matchContains: true,
                formatItem: function(row, i, max) {//显示出来的项格式
                    return i + "/" + max + ": \"" + row.ProductID + "\" [" + row.ProductName + "]";
                },
                formatMatch: function(row, i, max) {
                    return row.ProductName; //用户输入的内容在哪些数据项里面搜索。例如现在是在productName搜索,若要加上ProductID则为 return row.productID+" "+ row.ProductName;
                },
                formatResult: function(row) {
                    return row.ProductName;
                }
            };
            //autocomplete初始化函数
            function initAutoComplete(json) {
                $("#inputName").autocomplete(json, options);
                $("#inputName").result(function(event, data, formatted) {//data 选中的行json对象. formatted是formatMatch返回的值.
                    $("#inputId").val(data.ProductID);
                });
            }
            /*==========加载时执行的语句==========*/
            $(function() {
                //加载城市数据, 并在回调函数中用返回的数据初始化autocomplete
                $.getJSON("products.ashx", {}, function(json) {
                    initAutoComplete(json);
                })
            });        
        </script>
        <link href="jquery.autocomplete.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div class="ui-widget ui-widget-content ui-corner-all" style=" 700px; padding: 5px;">
            <h3>
                Demo. 应用AutoComplete插件 </h3>
            <br style="clear: both" />
            <div class="formLabel">
                <label for="inputName">请输入城市拼音和汉字:</label>
            </div>
            <div class="formInput">
                <input id="inputName" name="inputName" type="text" />
            </div>
            <br style="clear:both" />
            <br style="clear: both" />
            <div class="formLabel">
                <label for="inputId">城市ID:</label></div>
            <div class="formInput">
                <input id="inputId" name="inputId" type="text" /></div>
            <br style="clear: both" />
            <br style="clear: both" />
        </div>
    </body>
  • 相关阅读:
    二维数组
    ASCII_02_扩展
    ASCII_01
    【转】如何监控某个驱动器或目录及其下面的所有子目录的创建文件的动作
    webpack+vue2.0项目 (一) vue-cli脚手架
    分享两个常用的rem布局方式
    移动端border:1px问题解决方案
    sticky footer 布局
    用js数组实现最原始的图片轮播实现
    分享按钮(QQ,微信,微博等)移入动画效果
  • 原文地址:https://www.cnblogs.com/jianjialin/p/1598913.html
Copyright © 2011-2022 走看看