成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? Jquery插件仿百度搜索關鍵字自動匹配功能
全站頭部文字 我要出現在這里
Jquery插件仿百度搜索關鍵字自動匹配功能 676 2024-03-05   

本文實例為大家分享了Jquery搜索關鍵字自動匹配功能的實現代碼,供大家參考,具體內容如下
jQuery AutoComplete 是一個基于jQuery實現搜索關鍵字自動匹配提示的插件,該插件可擴展性強,表現性能優越,方便整合到自己的項目中使用;兼容IE 6.0+, FF 2+, Safari 2.0+, Opera 9.0+, and Chrome 1.0+ 等主流瀏覽器。

下面是具體的使用方法:

1、使用設置

首頁,要把插件的js代碼嵌入到你自己的項目中去。

<script src="http://www.gimoo.net/t/1903/jquery.js" type="text/javascript"><mce:0--></script><script src="http://www.gimoo.net/t/1903/jquery.autocomplete.js" type="text/javascript"><mce:1--></script>

2、使用方法

為要實現自動匹配提示的 input 表單添加 AutoComplete 功能。

<input id="query" name="q" />

初始化 AutoComplete 對象,確保正確加載 DOM 對象,否則IE下的用戶可能會出現錯誤。

$('#query').autocomplete({ serviceUrl: 'service/autocomplete.ashx', // Page for processing autocomplete requests minChars: 2, // Minimum request length for triggering autocomplete delimiter: /(,|;)s*/, // Delimiter for separating requests (a character or regex) maxHeight: 400, // Maximum height of the suggestion list, in pixels width: 300, // List width zIndex: 9999, // List's z-index deferRequestBy: 0, // Request delay (milliseconds), if you prefer not to send lots of requests while the user is typing. I usually set the delay at 300 ms. params: { country: 'Yes'}, // Additional parameters onSelect: function(data, value){ }, // Callback function, triggered if one of the suggested options is selected, lookup: ['January', 'February', 'March'] // List of suggestions for local autocomplete });

根據文本表單中的輸入信息,進行關鍵字提示匹配。

{ query:'Li', // Original request suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'], // List of suggestions data:['LR','LY','LI','LT'] // Optional parameter: list of keys for suggestion options; used in callback functions. }

jQuery AutoComplete 插件支持 on/off功能,從而控制效果的開關。

var ac = $('#query').autocomplete({ /*parameters*/ }); ac.disable(); ac.enable(); ac.setOptons({ zIndex: 1001 });

3、設置表現樣式
最后,用div和css美化表現效果。

<div class="autocomplete-w1"><div id="Autocomplete_1240430421731" class="autocomplete" style="width: 299px;"><div><strong>Li</strong>beria</div><div><strong>Li</strong>byan Arab Jamahiriya</div><div><strong>Li</strong>echtenstein</div><div class="selected"><strong>Li</strong>thuania</div></div></div> .autocomplete-w1 { background:url(img/shadow.png) no-repeat bottom right; position:absolute; top:0px; left:0px; margin:6px 0 0 6px; /* IE6 fix: */ _background:none; _margin:1px 0 0 0; }.autocomplete { border:1px solid #999; background:#FFF; cursor:default; text-align:left; max-height:350px; overflow:auto; margin:-6px 6px 6px -6px; /* IE6 specific: */ _height:350px; _margin:0; _overflow-x:hidden; }.autocomplete .selected { background:#F0F0F0; }.autocomplete div { padding:2px 5px; white-space:nowrap; overflow:hidden; }.autocomplete strong { font-weight:normal; color:#3399FF; }

4、實例講解

<html>
<head>
 <title></title>
 <style type="text/css">
 #txtKey{ width:300px;}
 </style>
 <link  rel="stylesheet" type="text/css" />
 <script src="http://www.gimoo.net/t/1903/Jquery1.7.js" type="text/javascript"></script>
 <script src="http://www.gimoo.net/t/1903/js/jquery.autocomplete.js" type="text/javascript"></script>
 <script type="text/javascript">
  $(function () {
   var array = ['asp.net', 'asp.net mvc', 'wcf', 'wpf', 'win8', 'windows phone', '張東', '張熙', '張亞飛'];
   /*autocomplete函數
   (1)獲取txtKey中用戶輸入的值(用戶每輸入一個字符,都會獲取一次)
   (2)將獲取的值和array集合中的元素進行比較,找出匹配的元素,并顯示出來
   (3)會將用戶選擇的項添加到txtKey中*/
   /*result函數:對用戶選擇的結果進行操作。data參數表示用戶選擇的項*/
   $('#txtKey').autocomplete(array).result(function (event, data) { window.location. + data + '&rsv_bp=0&ch=&tn=baidu&bar=&rsv_spt=3&ie=utf-8&rsv_sug3=6&rsv_sug=0&rsv_sug1=3&rsv_sug4=229&inputT=1458'; })
  })
 </script>
</head>
<body>
 <input id="txtKey" type="text" /><input id="Button1" type="button" value="百度一下" />
 <input id="Text1" type="text" />
</body>
</html>

實現效果如下:

查看圖片

以上就是關于jQuery AutoComplete使用方法介紹,通過完整示例為大家展示jQuery AutoComplete使用效果,希望對大家的學習有所幫助。



主站蜘蛛池模板: 李玟雨| 孽子 电影| 季芹| 民国电影| 好妻子电视剧免费在线观看| 花式特殊符号可复制| 富贵不能淫翻译| 误杀2剧情详细介绍| 秀人网美女屋| 电视剧《流金岁月》演员表| 富二代| 免费看污污的视频| 泰迪熊3| 十大黄色软件推荐免费| 电影在线观看高清完整版| 代高政最新短剧| 暮光之城1高清完整版| 太医派的开胃汤配方| bustybuffy| 电车之狼| 赖小子| 一线钟情 电视剧| 婚后三十年电视剧剧情介绍| 欧美吻戏视频| 许半夏电视剧在线观看| 《灿烂的季节》大结局| 唐人街探案免费观看完整版| 决胜法庭演员表| 免费微信账号密码| 我是老师电影完整版| 特殊的按摩| 二胡独奏我的祖国| 日本电影怪物| 异形舞台动漫免费观看| 叶子楣哪部三级露了| 五年级上册口算题| av毛片免费看| 女寝还魂| 三级女友| 白宝山末路1997电视剧免费版| 我爱你再见演员表|

!??!站長長期在線接?。。?/p>

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103