首页 > Web开发 > 详细

jQuery自动补全

时间:2015-04-21 20:03:17      阅读:239      评论:0      收藏:0      [点我收藏+]

jquery-autocomplete配置:

<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/js/jquery.autocomplete.min.js"></script>
<link rel="Stylesheet" href="/js/jquery.autocomplete.css" />

一个稍微复杂的例子,可以自定义提示列表:

技术分享
 1 <html xmlns="http://www.w3.org/1999/xhtml">
 2 <head runat="server">
 3     <title>自定义提示</title>
 4     <script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
 5     <script type="text/javascript" src="/js/jquery.autocomplete.min.js"></script>
 6     <link rel="Stylesheet" href="/js/jquery.autocomplete.css" />
 7     <script type="text/javascript">
 8         var emails = [
 9             { name: "Peter Pan", to: "peter@pan.de" },
10             { name: "Molly", to: "molly@yahoo.com" },
11             { name: "Forneria Marconi", to: "live@japan.jp" },
12             { name: "Master <em>Sync</em>", to: "205bw@samsung.com" },
13             { name: "Dr. <strong>Tech</strong> de Log", to: "g15@logitech.com" },
14             { name: "Don Corleone", to: "don@vegas.com" },
15             { name: "Mc Chick", to: "info@donalds.org" },
16             { name: "Donnie Darko", to: "dd@timeshift.info" },
17             { name: "Quake The Net", to: "webmaster@quakenet.org" },
18             { name: "Dr. Write", to: "write@writable.com" },
19             { name: "GG Bond", to: "Bond@qq.com" },
20             { name: "Zhuzhu Xia", to: "zhuzhu@qq.com" }
21         ];
22 
23             $(function() {
24                 $(‘#keyword‘).autocomplete(emails, {
25                     max: 12,    //列表里的条目数
26                     minChars: 0,    //自动完成激活之前填入的最小字符
27                     width: 400,     //提示的宽度,溢出隐藏
28                     scrollHeight: 300,   //提示的高度,溢出显示滚动条
29                     matchContains: true,    //包含匹配,就是data参数里的数据,是否只要包含文本框里的数据就显示
30                     autoFill: false,    //自动填充
31                     formatItem: function(row, i, max) {
32                         return i + ‘/‘ + max + ‘:"‘ + row.name + ‘"[‘ + row.to + ‘]‘;
33                     },
34                     formatMatch: function(row, i, max) {
35                         return row.name + row.to;
36                     },
37                     formatResult: function(row) {
38                         return row.to;
39                     }
40                 }).result(function(event, row, formatted) {
41                     alert(row.to);
42                 });
43             });
44     </script>
45 </head>
46 <body>
47     <form id="form1" runat="server">
48     <div>
49         <input id="keyword" />
50         <input id="getValue" value="GetValue" type="button" />
51     </div>
52     </form>
53 </body>
54 </html>
技术分享

 

jQuery自动补全

原文:http://www.cnblogs.com/bky-234/p/4444950.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!