国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

jquery php百度搜索框智能提示效果

2024-05-04 21:48:47
字體:
來源:轉載
供稿:網友

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

php文件,代碼如下:

  1. <?php 
  2.  
  3.     mysql_connect('localhost''root' ,'root'); 
  4.  mysql_select_db("autoComplete");  
  5.  
  6.  $queryString = $_POST['queryString']; 
  7.    //開源代碼Vevb.com 
  8.    if(strlen($queryString) >0) { 
  9.     $sql"SELECT value FROM countries WHERE value LIKE '".$queryString."%' LIMIT 10"
  10.     $query = mysql_query($sql); 
  11.     while ($result = mysql_fetch_array($query,MYSQL_BOTH)){      
  12.      $value=$result['value']; 
  13.      echo '<li onClick="fill(''.$value.'');">'.$value.'</li>'
  14.     } 
  15.  
  16.    }  
  17.  
  18. ?> 

sql.sql把這里復制保存到你的數據庫,代碼如下:

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

注:里面有個jquery文件沒有放上來,大家可以下載jquery庫.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 罗定市| 谷城县| 十堰市| 云林县| 阿拉善右旗| 闽清县| 聊城市| 屏山县| 巴彦县| 电白县| 安徽省| 克东县| 临清市| 团风县| 余庆县| 威远县| 肥城市| 肇州县| 平陆县| 如皋市| 景东| 永和县| 洛隆县| 张家界市| 安远县| 禄丰县| 库尔勒市| 亳州市| 尼木县| 宜兰市| 壶关县| 天津市| 哈尔滨市| 金平| 清新县| 沽源县| 湘潭市| 房产| 长海县| 安徽省| 延吉市|