博客导读网

一个让你随便看看的地方

jQuery插件之AutoComplete使用实例

推荐
记录人生轨迹,寻找人生航向!

<link rel="stylesheet" href="jquery.autocomplete.css" type="text/css" />

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

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

 

<script type="text/javascript">
        /*==========用户自定义方法==========*/
        //城市数据
        var cityList;
        //autocomplete选项
        var options = {
            minChars: 1,
            max: 500,
            width: 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="width: 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>

0
0
0
(请您对文章做出评价)
原文地址:http://chenling1018.blog.163.com/blog/static/1480254201012504421495

记录人生轨迹,寻找人生航向!的其他文章
Ubuntu启动时显示 No resume image,无法进入图形界面 PHP动态编译出现Cannot find autoconf
phpize简介(实例应用) SugarSync替代Dropbox
find 命令介绍 HTML:scrollLeft,scrollWidth,clientWidth,offsetWidth 之完全详解(转载)
仿QQ空间相册上下页效果参考JS CSS3属性box-shadow(阴影效果)使用教程
Ubuntu 下误改sudoers而无法使用sudo解决(忘记root密码时也可以这样找回) Ubuntu修改/etc/sudoers 失败的解决方法
更多...

© 2010 博客导读网 BlogABC.NET 本站所有内容皆由网友推荐而来,所有博文的版权归原作者所有,如有冒犯,请邮件告知。uncracker#gmail.com