jquery autocomplete demo

Search and filter based on user-entered values, allowing users to quickly find and select from a list of preset values.

<html>
<head>
    <title>jquery autocomplete demo</title>
    <meta http-equiv="content-type" content="text/html; charset=gbk" />
    <script src="<%=path%>/auto/jquery-1.7.1.min.js"></script>
    <script src="<%=path%>/auto/jquery.autocomplete.js"></script>
    <link rel="stylesheet" href="<%=path%>/auto/jquery.autocomplete.css" />
    <script type='text/javascript'>
            //可改成ajax变成动态数据
            var address = [
            { name: "西安", to: "xian" },
            { name: "北京", to: "beijing" },
            { name: "西宁", to: "xining" },
            { name: "西藏", to: "xizang" },
            { name: "天津", to: "tianjin" },
            ]; 
            $(function(){
                $('#keyword').autocomplete(address, {
                    max: 12, //列表里的条目数
                    minChars: 1, //自动完成激活之前填入的最小字符
                    width: 200, //提示的宽度,溢出隐藏
                    scrollHeight: 300, //提示的高度,溢出显示滚动条
                    matchContains: true, //包含匹配,就是data参数里的数据,是否只要包含文本框里的数据就显示
                    autoFill: false, //自动填充
                    formatItem: function(row, i, max) {
                        return row.name;
                    },formatMatch: function(row, i, max) {
                        return row.name + row.to;
                    },formatResult: function(row) {
                        return row.to;
                    }
                });
            });
        </script>
</head>
<body>
        <h1>jquery autocomplete demo</h1>
        <h1>
            <input type="text" id="keyword"  style="width: 200px;"/>
        </h1>
    </body>
</html>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326662272&siteId=291194637