jquery php百度搜索框智能提示效果
这个程序是利用php+ajax+jquery 实现的一个仿baidu智能提示的效果,有需要的朋友可以下载测试,代码如下:
index.html文件,保保存成index.htm,代码如下:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Ajax Auto Suggest</title> <script type="text/javascript" src="jquery-1.2.1.pack.js"></script> <script type="text/javascript"> function lookup(inputString) { if (inputString.length == 0) { // Hide the suggestion box. $('#suggestions').hide(); } else { $.post("rpc.php", { queryString : "" + inputString + "" }, function (data) { if (data.length > 0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } }); } } // lookup function fill(thisValue) { $('#inputString').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } </script> <style type="text/css"> body { font-family: Helvetica; font-size: 11px; color: #000; } h3 { margin: 0px; padding: 0px; } .suggestionsBox { position: relative; left: 30px; margin: 10px 0px 0px 0px; width: 200px; background-color: #212427; -moz-border-radius: 7px; -webkit-border-radius: 7px; border: 2px solid #000; color: #fff; } .suggestionList { margin: 0px; padding: 0px; } .suggestionList li { margin: 0px 0px 3px 0px; padding: 3px; cursor: pointer; } .suggestionList li:hover { background-color: #659CD8; } </style> </head> <body> <div> <form> <div> Type your county: <br /> <input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" /> </div> <div class="suggestionsBox" id="suggestions" style="display: none;"> <img src="/static/imghw/default1.png" data-src="upArrow.png" class="lazy" style="max-width:90%" alt="upArrow" /> <div class="suggestionList" id="autoSuggestionsList"> </div> </div> </form> </div> </body> </html> php文件,代码如下: <?php mysql_connect('localhost', 'root' ,'root'); mysql_select_db("autoComplete"); $queryString = $_POST['queryString']; //开源代码phprm.com if(strlen($queryString) >0) { $sql= "SELECT value FROM countries WHERE value LIKE '".$queryString."%' LIMIT 10"; $query = mysql_query($sql); while ($result = mysql_fetch_array($query,MYSQL_BOTH)){ $value=$result['value']; echo '<li onClick="fill(''.$value.'');">'.$value.'</li>'; } } ?>
로그인 후 복사
sql.sql把这里复制保存到你的数据库,代码如下:
-- phpMyAdmin SQL Dump -- version 3.3.5 -- http://www.phpmyadmin.net -- -- 主机: localhost -- 生成日期: 2010 年 12 月 09 日 02:36 -- 服务器版本: 5.0.22 -- PHP 版本: 5.2.14 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- 数据库: `autoComplete` -- -- -------------------------------------------------------- -- -- 表的结构 `countries` -- CREATE TABLE IF NOT EXISTS `countries` ( `id` int(6) NOT NULL auto_increment, `value` varchar(250) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=243 ; -- -- 转存表中的数据 `countries` -- INSERT INTO `countries` (`id`, `value`) VALUES (1, 'Afghanistan'), (2, 'Aringland Islands'), (3, 'Albania'), (4, 'Algeria'), (5, 'American Samoa'), (6, 'Andorra'), (7, 'Angola'), (8, 'Anguilla'), (9, 'Antarctica'), (10, 'Antigua and Barbuda'), (11, 'Argentina'), (12, 'Armenia'), (13, 'Aruba'), (14, 'Australia'), (15, 'Austria'), (16, 'Azerbaijan'), (17, 'Bahamas'), (18, 'Bahrain'), (19, 'Bangladesh'), (20, 'Barbados'), (21, 'Belarus'), (22, 'Belgium'), (23, 'Belize'), (24, 'Benin'), (25, 'Bermuda'), (26, 'Bhutan'), (27, 'Bolivia'), (28, 'Bosnia and Herzegovina'), (29, 'Botswana'), (30, 'Bouvet Island'), (31, 'Brazil'), (32, 'British Indian Ocean territory'), (33, 'Brunei Darussalam'), (34, 'Bulgaria'), (35, 'Burkina Faso'), (36, 'Burundi'), (37, 'Cambodia'), (38, 'Cameroon'), (39, 'Canada'), (40, 'Cape Verde'), (41, 'Cayman Islands'), (42, 'Central African Republic'), (43, 'Chad'), (44, 'Chile'), (45, 'China'), (46, 'Christmas Island'), (47, 'Cocos (Keeling) Islands'), (48, 'Colombia'), (49, 'Comoros'), (50, 'Congo'), (51, 'Congo'), (52, ' Democratic Republic'), (53, 'Cook Islands'), (54, 'Costa Rica'), (55, 'Ivory Coast (Ivory Coast)'), (56, 'Croatia (Hrvatska)'), (57, 'Cuba'), (58, 'Cyprus'), (59, 'Czech Republic'), (60, 'Denmark'), (61, 'Djibouti'), (62, 'Dominica'), (63, 'Dominican Republic'), (64, 'East Timor'), (65, 'Ecuador'), (66, 'Egypt'), (67, 'El Salvador'), (68, 'Equatorial Guinea'), (69, 'Eritrea'), (70, 'Estonia'), (71, 'Ethiopia'), (72, 'Falkland Islands'), (73, 'Faroe Islands'), (74, 'Fiji'), (75, 'Finland'), (76, 'France'), (77, 'French Guiana'), (78, 'French Polynesia'), (79, 'French Southern Territories'), (80, 'Gabon'), (81, 'Gambia'), (82, 'Georgia'), (83, 'Germany'), (84, 'Ghana'), (85, 'Gibraltar'), (86, 'Greece'), (87, 'Greenland'), (88, 'Grenada'), (89, 'Guadeloupe'), (90, 'Guam'), (91, 'Guatemala'), (92, 'Guinea'), (93, 'Guinea-Bissau'), (94, 'Guyana'), (95, 'Haiti'), (96, 'Heard and McDonald Islands'), (97, 'Honduras'), (98, 'Hong Kong'), (99, 'Hungary'), (100, 'Iceland'), (101, 'India'), (102, 'Indonesia'), (103, 'Iran'), (104, 'Iraq'), (105, 'Ireland'), (106, 'Israel'), (107, 'Italy'), (108, 'Jamaica'), (109, 'Japan'), (110, 'Jordan'), (111, 'Kazakhstan'), (112, 'Kenya'), (113, 'Kiribati'), (114, 'Korea (north)'), (115, 'Korea (south)'), (116, 'Kuwait'), (117, 'Kyrgyzstan'), (118, 'Lao People''s Democratic Republic'), (119, 'Latvia'), (120, 'Lebanon'), (121, 'Lesotho'), (122, 'Liberia'), (123, 'Libyan Arab Jamahiriya'), (124, 'Liechtenstein'), (125, 'Lithuania'), (126, 'Luxembourg'), (127, 'Macao'), (128, 'Macedonia'), (129, 'Madagascar'), (130, 'Malawi'), (131, 'Malaysia'), (132, 'Maldives'), (133, 'Mali'), (134, 'Malta'), (135, 'Marshall Islands'), (136, 'Martinique'), (137, 'Mauritania'), (138, 'Mauritius'), (139, 'Mayotte'), (140, 'Mexico'), (141, 'Micronesia'), (142, 'Moldova'), (143, 'Monaco'), (144, 'Mongolia'), (145, 'Montserrat'), (146, 'Morocco'), (147, 'Mozambique'), (148, 'Myanmar'), (149, 'Namibia'), (150, 'Nauru'), (151, 'Nepal'), (152, 'Netherlands'), (153, 'Netherlands Antilles'), (154, 'New Caledonia'), (155, 'New Zealand'), (156, 'Nicaragua'), (157, 'Niger'), (158, 'Nigeria'), (159, 'Niue'), (160, 'Norfolk Island'), (161, 'Northern Mariana Islands'), (162, 'Norway'), (163, 'Oman'), (164, 'Pakistan'), (165, 'Palau'), (166, 'Palestinian Territories'), (167, 'Panama'), (168, 'Papua New Guinea'), (169, 'Paraguay'), (170, 'Peru'), (171, 'Philippines'), (172, 'Pitcairn'), (173, 'Poland'), (174, 'Portugal'), (175, 'Puerto Rico'), (176, 'Qatar'), (177, 'Runion'), (178, 'Romania'), (179, 'Russian Federation'), (180, 'Rwanda'), (181, 'Saint Helena'), (182, 'Saint Kitts and Nevis'), (183, 'Saint Lucia'), (184, 'Saint Pierre and Miquelon'), (185, 'Saint Vincent and the Grenadines'), (186, 'Samoa'), (187, 'San Marino'), (188, 'Sao Tome and Principe'), (189, 'Saudi Arabia'), (190, 'Senegal'), (191, 'Serbia and Montenegro'), (192, 'Seychelles'), (193, 'Sierra Leone'), (194, 'Singapore'), (195, 'Slovakia'), (196, 'Slovenia'), (197, 'Solomon Islands'), (198, 'Somalia'), (199, 'South Africa'), (200, 'South Georgia and the South Sandwich Islands'), (201, 'Spain'), (202, 'Sri Lanka'), (203, 'Sudan'), (204, 'Suriname'), (205, 'Svalbard and Jan Mayen Islands'), (206, 'Swaziland'), (207, 'Sweden'), (208, 'Switzerland'), (209, 'Syria'), (210, 'Taiwan'), (211, 'Tajikistan'), (212, 'Tanzania'), (213, 'Thailand'), (214, 'Togo'), (215, 'Tokelau'), (216, 'Tonga'), (217, 'Trinidad and Tobago'), (218, 'Tunisia'), (219, 'Turkey'), (220, 'Turkmenistan'), (221, 'Turks and Caicos Islands'), (222, 'Tuvalu'), (223, 'Uganda'), (224, 'Ukraine'), (225, 'United Arab Emirates'), (226, 'United Kingdom'), (227, 'United States of America'), (228, 'Uruguay'), (229, 'Uzbekistan'), (230, 'Vanuatu'), (231, 'Vatican City'), (232, 'Venezuela'), (233, 'Vietnam'), (234, 'Virgin Islands (British)'), (235, 'Virgin Islands (US)'), (236, 'Wallis and Futuna Islands'), (237, 'Western Sahara'), (238, 'Yemen'), (239, 'Zaire'), (240, 'Zambia'), (241, 'Zimbabwe');
로그인 후 복사
注:里面有个jquery文件没有放上来,大家可以下载jquery库.
文章网址:
随意转载^^但请附上教程地址。
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사
어 ass 신 크리드 그림자 : 조개 수수께끼 솔루션
3 몇 주 전
By DDD
Windows 11 KB5054979의 새로운 기능 및 업데이트 문제를 해결하는 방법
2 몇 주 전
By DDD
Atomfall에서 크레인 제어 키 카드를 찾을 수 있습니다
3 몇 주 전
By DDD
R.E.P.O. 저축 설명 (및 파일 저장)
1 몇 달 전
By 尊渡假赌尊渡假赌尊渡假赌
어 ass 신 크리드 섀도우 - 대장장이를 찾고 무기 및 갑옷 커스터마 화 잠금 해제 방법
4 몇 주 전
By DDD

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제
Gmail 이메일의 로그인 입구는 어디에 있나요?
7569
15


Cakephp 튜토리얼
1386
52


Steam의 계정 이름 형식은 무엇입니까?
87
11


Win11 활성화 키 영구
61
19


NYT 연결 힌트와 답변
28
106

