这个程序是利用php+ajax+jquery 实现的一个仿baidu智能提示的效果,有须要的朋友能够下载測试哦。

代码例如以下

index.html文件,保保存成index.htm

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Ajax Auto Suggest</title>
  6. <script type="text/javascript" src="jquery-1.2.1.pack.js"></script>
  7. <script type="text/javascript">
  8. function lookup(inputString) {
  9. if(inputString.length == 0) {
  10. // Hide the suggestion box.
  11. $('#suggestions').hide();
  12. } else {
  13. $.post("rpc.php", {queryString: ""+inputString+""}, function(data){
  14. if(data.length >0) {
  15. $('#suggestions').show();
  16. $('#autoSuggestionsList').html(data);
  17. }
  18. });
  19. }
  20. } // lookup
  21.  
  22. function fill(thisValue) {
  23. $('#inputString').val(thisValue);
  24. setTimeout("$('#suggestions').hide();", 200);
  25. }
  26. </script>
  27. <style type="text/css">
  28. body {
  29. font-family: Helvetica;
  30. font-size: 11px;
  31. color: #000;
  32. }
  33.  
  34. h3 {
  35. margin: 0px;
  36. padding: 0px;
  37. }
  38. .suggestionsBox {
  39. position: relative;
  40. left: 30px;
  41. margin: 10px 0px 0px 0px;
  42. width: 200px;
  43. background-color: #212427;
  44. -moz-border-radius: 7px;
  45. -webkit-border-radius: 7px;
  46. border: 2px solid #000;
  47. color: #fff;
  48. }
  49.  
  50. .suggestionList {
  51. margin: 0px;
  52. padding: 0px;
  53. }
  54.  
  55. .suggestionList li {
  56.  
  57. margin: 0px 0px 3px 0px;
  58. padding: 3px;
  59. cursor: pointer;
  60. }
  61.  
  62. .suggestionList li:hover {
  63. background-color: #659CD8;
  64. }
  65. </style>
  66. </head>
  67. <body>
  68.  
  69. <div>
  70. <form>
  71. <div>
  72. Type your county:
  73. <br />
  74. <input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" />
  75. </div>
  76.  
  77. <div class="suggestionsBox" id="suggestions" style="display: none;">
  78. <img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
  79. <div class="suggestionList" id="autoSuggestionsList">
  80.  
  81. </div>
  82. </div>
  83. </form>
  84. </div>
  85. </body>
  86. </html>

php文件

  1. <?php
  2. header('content-type:text/html;charset=utf-8');
  3. mysql_connect('localhost', 'root' ,'');
  4. mysql_select_db("test");
  5. mysql_query("set names utf8");
  6. $queryString = $_POST['queryString'];
  7. if(strlen($queryString) >0) {
  8. $sql= "SELECT value FROM countries WHERE value LIKE '".$queryString."%' LIMIT 10";
  9. $query = mysql_query($sql);
  10. while ($result = mysql_fetch_array($query,MYSQL_BOTH)){
  11. $value=$result['value'];
  12. ?>
  13. <li onClick="fill('<?=$value?>')"><?
  14.  
  15. =$value?></li>
  16. <?php
  17. }
  18. }
  19. ?>

sql.sql把这里复制保存到你的数据库教程

  1. CREATE TABLE IF NOT EXISTS `countries` (
  2. `id` int(6) NOT NULL auto_increment,
  3. `value` varchar(250) NOT NULL default '',
  4. PRIMARY KEY (`id`)
  5. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=243 ;
  6.  
  7. --
  8. -- 转存表中的数据 `countries`
  9. --
  10.  
  11. INSERT INTO `countries` (`id`, `value`) VALUES
  12. (1, 'Afghanistan'),
  13. (2, 'Aringland Islands'),
  14. (3, 'Albania'),
  15. (4, 'Algeria'),
  16. (5, 'American Samoa'),
  17. (6, 'Andorra'),
  18. (7, 'Angola'),
  19. (8, 'Anguilla'),
  20. (9, 'Antarctica'),
  21. (10, 'Antigua and Barbuda'),
  22. (11, 'Argentina'),
  23. (12, 'Armenia'),
  24. (13, 'Aruba'),
  25. (14, 'Australia'),
  26. (15, 'Austria'),
  27. (16, 'Azerbaijan'),
  28. (17, 'Bahamas'),
  29. (18, 'Bahrain'),
  30. (19, 'Bangladesh'),
  31. (20, 'Barbados'),
  32. (21, 'Belarus'),
  33. (22, 'Belgium'),
  34. (23, 'Belize'),
  35. (24, 'Benin'),
  36. (25, 'Bermuda'),
  37. (26, 'Bhutan'),
  38. (27, 'Bolivia'),
  39. (28, 'Bosnia and Herzegovina'),
  40. (29, 'Botswana'),
  41. (30, 'Bouvet Island'),
  42. (31, 'Brazil'),
  43. (32, 'British Indian Ocean territory'),
  44. (33, 'Brunei Darussalam'),
  45. (34, 'Bulgaria'),
  46. (35, 'Burkina Faso'),
  47. (36, 'Burundi'),
  48. (37, 'Cambodia'),
  49. (38, 'Cameroon'),
  50. (39, 'Canada'),
  51. (40, 'Cape Verde'),
  52. (41, 'Cayman Islands'),
  53. (42, 'Central African Republic'),
  54. (43, 'Chad'),
  55. (44, 'Chile'),
  56. (45, 'China'),
  57. (46, 'Christmas Island'),
  58. (47, 'Cocos (Keeling) Islands'),
  59. (48, 'Colombia'),
  60. (49, 'Comoros'),
  61. (50, 'Congo'),
  62. (51, 'Congo'),
  63. (52, ' Democratic Republic'),
  64. (53, 'Cook Islands'),
  65. (54, 'Costa Rica'),
  66. (55, 'Ivory Coast (Ivory Coast)'),
  67. (56, 'Croatia (Hrvatska)'),
  68. (57, 'Cuba'),
  69. (58, 'Cyprus'),
  70. (59, 'Czech Republic'),
  71. (60, 'Denmark'),
  72. (61, 'Djibouti'),
  73. (62, 'Dominica'),
  74. (63, 'Dominican Republic'),
  75. (64, 'East Timor'),
  76. (65, 'Ecuador'),
  77. (66, 'Egypt'),
  78. (67, 'El Salvador'),
  79. (68, 'Equatorial Guinea'),
  80. (69, 'Eritrea'),
  81. (70, 'Estonia'),
  82. (71, 'Ethiopia'),
  83. (72, 'Falkland Islands'),
  84. (73, 'Faroe Islands'),
  85. (74, 'Fiji'),
  86. (75, 'Finland'),
  87. (76, 'France'),
  88. (77, 'French Guiana'),
  89. (78, 'French Polynesia'),
  90. (79, 'French Southern Territories'),
  91. (80, 'Gabon'),
  92. (81, 'Gambia'),
  93. (82, 'Georgia'),
  94. (83, 'Germany'),
  95. (84, 'Ghana'),
  96. (85, 'Gibraltar'),
  97. (86, 'Greece'),
  98. (87, 'Greenland'),
  99. (88, 'Grenada'),
  100. (89, 'Guadeloupe'),
  101. (90, 'Guam'),
  102. (91, 'Guatemala'),
  103. (92, 'Guinea'),
  104. (93, 'Guinea-Bissau'),
  105. (94, 'Guyana'),
  106. (95, 'Haiti'),
  107. (96, 'Heard and McDonald Islands'),
  108. (97, 'Honduras'),
  109. (98, 'Hong Kong'),
  110. (99, 'Hungary'),
  111. (100, 'Iceland'),
  112. (101, 'India'),
  113. (102, 'Indonesia'),
  114. (103, 'Iran'),
  115. (104, 'Iraq'),
  116. (105, 'Ireland'),
  117. (106, 'Israel'),
  118. (107, 'Italy'),
  119. (108, 'Jamaica'),
  120. (109, 'Japan'),
  121. (110, 'Jordan'),
  122. (111, 'Kazakhstan'),
  123. (112, 'Kenya'),
  124. (113, 'Kiribati'),
  125. (114, 'Korea (north)'),
  126. (115, 'Korea (south)'),
  127. (116, 'Kuwait'),
  128. (117, 'Kyrgyzstan'),
  129. (118, 'Lao People''s Democratic Republic'),
  130. (119, 'Latvia'),
  131. (120, 'Lebanon'),
  132. (121, 'Lesotho'),
  133. (122, 'Liberia'),
  134. (123, 'Libyan Arab Jamahiriya'),
  135. (124, 'Liechtenstein'),
  136. (125, 'Lithuania'),
  137. (126, 'Luxembourg'),
  138. (127, 'Macao'),
  139. (128, 'Macedonia'),
  140. (129, 'Madagascar'),
  141. (130, 'Malawi'),
  142. (131, 'Malaysia'),
  143. (132, 'Maldives'),
  144. (133, 'Mali'),
  145. (134, 'Malta'),
  146. (135, 'Marshall Islands'),
  147. (136, 'Martinique'),
  148. (137, 'Mauritania'),
  149. (138, 'Mauritius'),
  150. (139, 'Mayotte'),
  151. (140, 'Mexico'),
  152. (141, 'Micronesia'),
  153. (142, 'Moldova'),
  154. (143, 'Monaco'),
  155. (144, 'Mongolia'),
  156. (145, 'Montserrat'),
  157. (146, 'Morocco'),
  158. (147, 'Mozambique'),
  159. (148, 'Myanmar'),
  160. (149, 'Namibia'),
  161. (150, 'Nauru'),
  162. (151, 'Nepal'),
  163. (152, 'Netherlands'),
  164. (153, 'Netherlands Antilles'),
  165. (154, 'New Caledonia'),
  166. (155, 'New Zealand'),
  167. (156, 'Nicaragua'),
  168. (157, 'Niger'),
  169. (158, 'Nigeria'),
  170. (159, 'Niue'),
  171. (160, 'Norfolk Island'),
  172. (161, 'Northern Mariana Islands'),
  173. (162, 'Norway'),
  174. (163, 'Oman'),
  175. (164, 'Pakistan'),
  176. (165, 'Palau'),
  177. (166, 'Palestinian Territories'),
  178. (167, 'Panama'),
  179. (168, 'Papua New Guinea'),
  180. (169, 'Paraguay'),
  181. (170, 'Peru'),
  182. (171, 'Philippines'),
  183. (172, 'Pitcairn'),
  184. (173, 'Poland'),
  185. (174, 'Portugal'),
  186. (175, 'Puerto Rico'),
  187. (176, 'Qatar'),
  188. (177, 'Runion'),
  189. (178, 'Romania'),
  190. (179, 'Russian Federation'),
  191. (180, 'Rwanda'),
  192. (181, 'Saint Helena'),
  193. (182, 'Saint Kitts and Nevis'),
  194. (183, 'Saint Lucia'),
  195. (184, 'Saint Pierre and Miquelon'),
  196. (185, 'Saint Vincent and the Grenadines'),
  197. (186, 'Samoa'),
  198. (187, 'San Marino'),
  199. (188, 'Sao Tome and Principe'),
  200. (189, 'Saudi Arabia'),
  201. (190, 'Senegal'),
  202. (191, 'Serbia and Montenegro'),
  203. (192, 'Seychelles'),
  204. (193, 'Sierra Leone'),
  205. (194, 'Singapore'),
  206. (195, 'Slovakia'),
  207. (196, 'Slovenia'),
  208. (197, 'Solomon Islands'),
  209. (198, 'Somalia'),
  210. (199, 'South Africa'),
  211. (200, 'South Georgia and the South Sandwich Islands'),
  212. (201, 'Spain'),
  213. (202, 'Sri Lanka'),
  214. (203, 'Sudan'),
  215. (204, 'Suriname'),
  216. (205, 'Svalbard and Jan Mayen Islands'),
  217. (206, 'Swaziland'),
  218. (207, 'Sweden'),
  219. (208, 'Switzerland'),
  220. (209, 'Syria'),
  221. (210, 'Taiwan'),
  222. (211, 'Tajikistan'),
  223. (212, 'Tanzania'),
  224. (213, 'Thailand'),
  225. (214, 'Togo'),
  226. (215, 'Tokelau'),
  227. (216, 'Tonga'),
  228. (217, 'Trinidad and Tobago'),
  229. (218, 'Tunisia'),
  230. (219, 'Turkey'),
  231. (220, 'Turkmenistan'),
  232. (221, 'Turks and Caicos Islands'),
  233. (222, 'Tuvalu'),
  234. (223, 'Uganda'),
  235. (224, 'Ukraine'),
  236. (225, 'United Arab Emirates'),
  237. (226, 'United Kingdom'),
  238. (227, 'United States of America'),
  239. (228, 'Uruguay'),
  240. (229, 'Uzbekistan'),
  241. (230, 'Vanuatu'),
  242. (231, 'Vatican City'),
  243. (232, 'Venezuela'),
  244. (233, 'Vietnam'),
  245. (234, 'Virgin Islands (British)'),
  246. (235, 'Virgin Islands (US)'),
  247. (236, 'Wallis and Futuna Islands'),
  248. (237, 'Western Sahara'),
  249. (238, 'Yemen'),
  250. (239, 'Zaire'),
  251. (240, 'Zambia'),
  252. (241, 'Zimbabwe');

版权声明:本文博主原创文章,博客,未经同意不得转载。

jquery php 百度搜索框智能提示效果的更多相关文章

  1. js中实现输入框类似百度搜索的智能提示效果

    说明:我这里显示的数据采用词典(词典在js中自定义的,看下面文字),主要显示key. 页面元素: <style type="text/css">.search { le ...

  2. ajax实现异步前后台交互,模拟百度搜索框智能提示

    1.什么是异步?在传统的网站项目中,填写一堆数据,最后点击提交,在点击提交的这一刻才实现数据提交,前后台交互.在你点击提交之前数据是没有提交到后台的.这样就会造成很大的不便.比如,我填了一大堆数据,结 ...

  3. 使用jsonp跨域调用百度js实现搜索框智能提示,并实现鼠标和键盘对弹出框里候选词的操作【附源码】

    项目中常常用到搜索,特别是导航类的网站.自己做关键字搜索不太现实,直接调用百度的是最好的选择.使用jquery.ajax的jsonp方法可以异域调用到百度的js并拿到返回值,当然$.getScript ...

  4. 使用jsonp跨域调用百度js实现搜索框智能提示(转)

    http://www.cnblogs.com/oppoic/p/baidu_auto_complete.html 项目中常常用到搜索,特别是导航类的网站.自己做关键字搜索不太现实,直接调用百度的是最好 ...

  5. Servlet+Ajax实现搜索框智能提示

    简介:搜索框相信大家都不陌生,几乎每天都会在各类网站进行着搜索.有没有注意到,很多的搜索功能,当输入内容时,下面会出现提示.这类提示就叫做搜索框的智能提示,本门课程就为大家介绍如何使用Servlet和 ...

  6. Ternary Search Tree 应用--搜索框智能提示

    前面介绍了Ternary Search Tree和它的实现,那么可以用Ternary Search Tree来实现搜索框的只能提示,因为Ternary Search Tree的前缀匹配效率是非常高的, ...

  7. Ajax跨域实现淘宝/百度搜索下拉提示效果

    最近学到Ajax,觉得自己对与前后端的数据交互有了一个基本的了解.下面是Ajax应用到淘宝/百度的搜索功能的一个简单的小实例,就是输入一个词,下拉框中自动显示匹配的内容:

  8. 用jQuery实现搜索框的过滤效果

    遇到的问题: 1.动态添加了某些元素,在动态添加的某个元素上绑定事件失效 原因:因为需要绑定的元素的直接父元素也是动态添加的解决:向上为上一级父元素绑定事件 $(".check-box&qu ...

  9. Ajax跨域:Jsonp实例--百度搜索框下拉提示

    Ajax跨域:Jsonp实例--百度搜索框下拉提示 一.总结 一句话总结:a.找好接口:b.用script标签的src引入文件(json数据):c.定义及实现上一步引入文件中的函数 1.如何找到一个网 ...

随机推荐

  1. pig中使用的一些实例语法

    在pig中, dump和store会分别完毕两个MR, 不会一起进行 1:载入名用正則表達式: LOAD '/user/wizad/data/wizad/raw/2014-0{6,7-0,7-1,7- ...

  2. windows之实现3D立体效果的三种方法

    第一种:快捷键:win+tab 另外一种:cmd输入rundll32.exe dwmapi #105 第三种:使用软件bumptop

  3. Lua 与C 交换 第一篇

    编译 windows上编译lua源代码 cl /MD /O2 /W3 /c /DLUA_BUILD_AS_DLL *.c del *.o ren lua.obj lua.o ren luac.obj ...

  4. Android如何获得手机power_profile.xml文件

    上的能量消耗进行最近的测试,阅读文章一个月,最后,我们发现了一些新的想法,但产生的问题.那 工作无法再进行下去. 在Android手机中,对于手机中的每一个部件(cpu.led.gps.3g等等)执行 ...

  5. Android 大约Dialog弹出窗口

    直接效果图: 实现步骤: 1.主界面activity_main.xml非常easy,一个button <RelativeLayout xmlns:android="http://sch ...

  6. Oracle改变字段类型

    由于需求变化.现在,我们要一个类型NUMBER(8,2)字段类型改变 char. 总体思路如以下:       将要更改类型的字段名改名以备份,然后加入一个与要更改类型的字段名同名的字段(原字段已经改 ...

  7. Add/Remove listview web part in publish site via powershell

    1. Here is the code: Add WebPart in Publish Site Example : AddWebPartPublish http://localhost  " ...

  8. 【iOS】彩虹渐变色 的 Swift 实现

    首先很感谢大家的支持与关注.<Web Color 的 Swfit 实现>一文一经公布.訪问量迅速攀升,让本人受宠若惊. 为表达感激之情,今天早上把彩虹渐变也顺手实现了. 最新代码& ...

  9. 【原创】leetCodeOj --- Fraction to Recurring Decimal 解题报告

    原题地址: https://oj.leetcode.com/problems/fraction-to-recurring-decimal/ 题目内容: Given two integers repre ...

  10. JAVA学习课第二十八届(多线程(七))- 停止-threaded多-threaded面试题

    主密钥 /*  * wait 和 sleep 差别?  * 1.wait能够指定时间也能够不指定  * sleep必须指定时间  * 2.在同步中,对CPU的运行权和锁的处理不同  * wait释放运 ...