Jquery AutoComplete自動(dòng)完成 的使用方法實(shí)例
<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" />
首先是一個(gè)最簡(jiǎn)單的Autocomplete(自動(dòng)完成)代碼片段:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>AutoComplate</title>
<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" />
<script type="text/javascript">
$(function() {
var data = "Core Selectors Attributes Traversing Manipulation CSS Events Effects Ajax Utilities".split(" ");
$('#keyword').autocomplete(data).result(function(event, data, formatted) {
alert(data);
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="keyword" />
<input id="getValue" value="GetValue" type="button" />
</div>
</form>
</body>
</html>
result方法是jQuery Autocomplete插件里的重要方法,它在用戶在選定了某個(gè)條目時(shí)觸發(fā)。data參數(shù)為選中的數(shù)據(jù)。
一個(gè)稍微復(fù)雜的例子,可以自定義提示列表:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>自定義提示</title>
<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" />
<script type="text/javascript">
var emails = [
{ name: "Peter Pan", to: "peter@pan.de" },
{ name: "Molly", to: "molly@yahoo.com" },
{ name: "Forneria Marconi", to: "live@japan.jp" },
{ name: "Master <em>Sync</em>", to: "205bw@samsung.com" },
{ name: "Dr. <strong>Tech</strong> de Log", to: "g15@logitech.com" },
{ name: "Don Corleone", to: "don@vegas.com" },
{ name: "Mc Chick", to: "info@donalds.org" },
{ name: "Donnie Darko", to: "dd@timeshift.info" },
{ name: "Quake The Net", to: "webmaster@quakenet.org" },
{ name: "Dr. Write", to: "write@writable.com" },
{ name: "GG Bond", to: "Bond@qq.com" },
{ name: "Zhuzhu Xia", to: "zhuzhu@qq.com" }
];
$(function() {
$('#keyword').autocomplete(emails, {
max: 12, //列表里的條目數(shù)
minChars: 0, //自動(dòng)完成激活之前填入的最小字符
width: 400, //提示的寬度,溢出隱藏
scrollHeight: 300, //提示的高度,溢出顯示滾動(dòng)條
matchContains: true, //包含匹配,就是data參數(shù)里的數(shù)據(jù),是否只要包含文本框里的數(shù)據(jù)就顯示
autoFill: false, //自動(dòng)填充
formatItem: function(row, i, max) {
return i + '/' + max + ':"' + row.name + '"[' + row.to + ']';
},
formatMatch: function(row, i, max) {
return row.name + row.to;
},
formatResult: function(row) {
return row.to;
}
}).result(function(event, row, formatted) {
alert(row.to);
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="keyword" />
<input id="getValue" value="GetValue" type="button" />
</div>
</form>
</body>
</html>
formatItem、formatMatch、formatResult是自定提示信息的關(guān)鍵。
formatItem作用在于可以格式化列表中的條目,比如我們加了“I”,讓列表里的字顯示出了斜體。
formatMatch是配合formatItem使用,作用在于,由于使用了formatItem,所以條目中的內(nèi)容有所改變,而我們要匹配的是原始的數(shù)據(jù),所以用formatMatch做一個(gè)調(diào)整,使之匹配原始數(shù)據(jù),
formatResult是定義最終返回的數(shù)據(jù),比如我們還是要返回原始數(shù)據(jù),而不是formatItem過(guò)的數(shù)據(jù)。
jquery bassistance.de AutoComplete自動(dòng)完成效果代碼下載
- jQuery.Autocomplete實(shí)現(xiàn)自動(dòng)完成功能(詳解)
- jQuery UI AutoComplete 使用說(shuō)明
- jQuery UI Autocomplete 體驗(yàn)分享
- jQuery UI AutoComplete 自動(dòng)完成使用小記
- jQuery Autocomplete自動(dòng)完成插件
- JQuery autocomplete 使用手冊(cè)
- 基于jquery的文本框與autocomplete結(jié)合使用(asp.net+json)
- jQuery autocomplete插件修改
- jQuery Autocomplete簡(jiǎn)介_(kāi)動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
相關(guān)文章
jquery網(wǎng)頁(yè)回到頂部效果(圖標(biāo)漸隱,自寫(xiě))
當(dāng)網(wǎng)頁(yè)內(nèi)容草雞多的時(shí)候,用戶就需要有個(gè)按鈕快速回到頂部,于是用js來(lái)實(shí)現(xiàn)下,畫(huà)布多說(shuō),直接上代碼2014-06-06jQuery Ajax 全局調(diào)用封裝實(shí)例代碼詳解
這篇文章主要介紹了jQuery Ajax 全局調(diào)用封裝實(shí)例代碼詳解的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06jQuery用unbind方法去掉hover事件及其他方法介紹
jquery怎么去掉hover以為直接unbind(hover)就可以搞定,結(jié)果很失敗,接下來(lái)介紹下取消hover事件的多種方法,感興趣的你可以參考下哈2013-03-03easyui取消表單實(shí)時(shí)驗(yàn)證,提交時(shí)統(tǒng)一驗(yàn)證的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇easyui取消表單實(shí)時(shí)驗(yàn)證,提交時(shí)統(tǒng)一驗(yàn)證的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-11-11jQuery實(shí)現(xiàn)的下雪動(dòng)畫(huà)效果示例【附源碼下載】
這篇文章主要介紹了jQuery實(shí)現(xiàn)的下雪動(dòng)畫(huà)效果,涉及jQuery插件結(jié)合setInterval、animate進(jìn)行動(dòng)畫(huà)操作的相關(guān)使用技巧,并附帶源碼供讀者下載參考,需要的朋友可以參考下2018-02-02jquery的ajaxSubmit()異步上傳圖片并保存表單數(shù)據(jù)演示代碼
使用jquery的ajaxSubmit()異步上傳圖片的捅死實(shí)現(xiàn)保存表單數(shù)據(jù),具體演示代碼如下,感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助2013-06-06在jQuery中 關(guān)于json空對(duì)象篩選替換
本篇文章,小編將為大家介紹,在jQuery中 關(guān)于json空對(duì)象篩選替換,有需要的朋友可以參考一下2013-04-04textarea中的手動(dòng)換行處理的jquery代碼
textarea的手動(dòng)換行會(huì)產(chǎn)生換行標(biāo)志,但這個(gè)標(biāo)志存在卻看不到,存入數(shù)據(jù)庫(kù)中后讀出來(lái)顯示在頁(yè)面上卻不會(huì)換行,如何處理呢?2011-02-02