创建博客 登录  
 关注
   显示下一条  |  关闭

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

追求积极的人生,保持平和的心态,享受简单的生活。

 
 
 

日志

 
 

jQuery插件之AutoComplete使用实例  

2010-02-25 12:44:21|  分类: JavaScript秘籍 |  标签: |字号 订阅

<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
(请您对文章做出评价)
  评论这张
转发至微博
转发至微博
0   分享到:        
阅读(1743)| 评论(0)| 引用 (0) |举报

历史上的今天

相关文章

最近读者

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--相关文章--> <#--历史上的今天--> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2012