php百度搜索框代码,基于jquery的仿百度搜索框效果代码_jquery

先看看整个的效果图:

图一:

5661c8c263d37f4a73e7796cc0fd8558.gif

图二:

5f13f47aa8c58392ac99d073224988e3.gif

图三:

eeaba3d2300c7fe27db60a98baf7fd26.gif

图四:

ca4f8526ea53e4e99223906d84aa2ed3.gif

大概的效果图就这样,接下来直接看源码

页面:

CSS:

.autoSearchText{

border:solid 1px #CFCFCF;

height:20px;

color:Gray;

}

.menu_v{

margin:0;

padding:0;

line-height:20px;

font-size:12px;

list-style-type:none;

}

.menu_v li{

margin:0;

padding:0;

line-height:20px;

font-size:14px;

list-style-type:none;

float:none;

}

.menu_v li span{

color:Red;

}

#autoSearchItem{

border:solid 1px #CFCFCF;

visibility:hidden;

position:absolute;

background-color:white;

overflow-y:auto;

}

JS:

1 ///

2

3 (function($) {

4 var itemIndex = 0;

5

6 $.fn.autoSearchText = function(options) {

7 //以下为该插件的属性及其默认值

8 var deafult = {

9 width: 200, //文本框宽

itemHeight: 150, // 下拉框高

minChar: 1, //最小字符数(从第几个开始搜索)

datafn: null, //加载数据函数

fn: null //选择项后触发的回调函数

};

var textDefault = $(this).val();

var ops = $.extend(deafult, options);

$(this).width(ops.width);

var autoSearchItem = '

';

$(this).after(autoSearchItem);

$('#autoSearchItem').width(ops.width + 2); //设置项宽

$('#autoSearchItem').height(ops.itemHeight); //设置项高

$(this).focus(function() {

if ($(this).val() == textDefault) {

$(this).val('');

$(this).css('color', 'black');

}

});

var itemCount = $('li').length; //项个数

/*鼠标按下键时,显示下拉框,并且划过项时改变背景色及赋值给输入框*/

$(this).bind('keyup', function(e) {

if ($(this).val().length >= ops.minChar) {

var position = $(this).position();

$('#autoSearchItem').css({ 'visibility': 'visible', 'left': position.left, 'top': position.top + 24 });

var data = ops.datafn($(this).val());

initItem($(this), data);

var itemCount = $('li').length;

switch (e.keyCode) {

case 38: //上

if (itemIndex > 1) {

itemIndex--;

}

$('li:nth-child(' + itemIndex + ')').css({ 'background': 'blue', 'color': 'white' });

$(this).val($('li:nth-child(' + itemIndex + ')').find('font').text());

break;

case 40: //下

if (itemIndex < itemCount) {

itemIndex++;

}

$('li:nth-child(' + itemIndex + ')').css({ 'background': 'blue', 'color': 'white' });

$(this).val($('li:nth-child(' + itemIndex + ')').find('font').text());

break;

case 13: //Enter

if (itemIndex > 0 && itemIndex <= itemCount) {

$(this).val($('li:nth-child(' + itemIndex + ')').find('font').text());

$('#autoSearchItem').css('visibility', 'hidden');

ops.fn($(this).val());

}

break;

default:

break;

}

}

});

/*点击空白处隐藏下拉框*/

$(document).click(function() {

$('#autoSearchItem').css('visibility', 'hidden');

});

};

/*获取文本框的值*/

$.fn.getValue = function() {

return $(this).val();

};

/*初始化下拉框数据,鼠标移过每项时,改变背景色并且将项的值赋值给输入框*/

function initItem(obj, data) {

var str = "";

if (data.length == 0) {

$('#autoSearchItem ul').html('

无符合数据

');

}

else {

for (var i = 1; i <= data.length; i++) {

str += "

" + i + "/" + data.length + "\r" + data[i - 1] + "";

}

$('#autoSearchItem ul').html(str);

}

/*点击项时将值赋值给搜索文本框*/

$('li').each(function() {

$(this).bind('click', function() {

obj.val($(this).find('font').text());

$('#autoSearchItem').css('visibility', 'hidden');

});

});

/*鼠标划过每项时改变背景色*/

$('li').each(function() {

$(this).hover(

function() {

$('li:nth-child(' + itemIndex + ')').css({ 'background': 'white', 'color': 'black' });

itemIndex = $('li').index($(this)[0]) + 1;

$(this).css({ 'background': 'blue', 'color': 'white' });

obj.val($('li:nth-child(' + itemIndex + ')').find('font').text());

},

function() {

$(this).css({ 'background': 'white', 'color': 'black' });

}

);

});

};

})(jQuery);

getdata.ashx

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Services;

namespace table

{

/// /// $codebehindclassname$ 的摘要说明

///

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class getData : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

context.Response.Clear();

string value = GetResult();

context.Response.Write(value);

context.Response.End();

}

private string GetResult()

{

string result = string.Empty;

result = @"

[{""id"":""1"",""Code"":""1374123""},

{""id"":""2"",""Code"":""1374133""},

{""id"":""3"",""Code"":""1374143""},

{""id"":""4"",""Code"":""1374153""},

{""id"":""5"",""Code"":""1374163""},

{""id"":""6"",""Code"":""1374173""},

{""id"":""7"",""Code"":""1374183""},

{""id"":""8"",""Code"":""1374193""},

{""id"":""9"",""Code"":""1374213""},

{""id"":""10"",""Code"":""1374223""},

{""id"":""11"",""Code"":""1374233""},

{""id"":""12"",""Code"":""1374243""},

{""id"":""13"",""Code"":""1374253""},

{""id"":""14"",""Code"":""1374263""},

{""id"":""15"",""Code"":""1374273""},

{""id"":""16"",""Code"":""1374283""},

{""id"":""17"",""Code"":""1374293""},

{""id"":""18"",""Code"":""1374313""},

{""id"":""19"",""Code"":""1374323""},

{""id"":""20"",""Code"":""1374333""},

{""id"":""21"",""Code"":""1374343""},

{""id"":""22"",""Code"":""1374353""},

{""id"":""23"",""Code"":""1374363""},

{""id"":""24"",""Code"":""1374373""},

{""id"":""25"",""Code"":""1374383""},

{""id"":""26"",""Code"":""1374393""},

{""id"":""27"",""Code"":""1374403""},

{""id"":""28"",""Code"":""1374413""},

{""id"":""29"",""Code"":""1374423""},

{""id"":""30"",""Code"":""1374433""},

{""id"":""31"",""Code"":""1374443""},

{""id"":""32"",""Code"":""1374453""},

{""id"":""33"",""Code"":""1374463""},

{""id"":""34"",""Code"":""1374473""},

{""id"":""35"",""Code"":""1374483""},

{""id"":""36"",""Code"":""1374493""}]";

return result;

}

public bool IsReusable

{

get

{

return false;

}

}

}

}

Demo下载

相关标签:百度搜索框

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

相关文章

相关视频

网友评论

文明上网理性发言,请遵守 新闻评论服务协议我要评论

47d507a036d4dd65488c445c0974b649.png

立即提交

专题推荐064df72cb40df78e80e61b7041ee044f.png独孤九贱-php全栈开发教程

全栈 100W+

主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门

7dafe36c040e31d783922649aefe0be1.png玉女心经-web前端开发教程

入门 50W+

主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门

04246fdfe8958426b043c89ded0857f1.png天龙八部-实战开发教程

实战 80W+

主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441048.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【UVA - 227】Puzzle (模拟,水题)

题干&#xff1a; Puzzle A childrens puzzle that was popular 30 years ago consisted of a 5x5 frame which contained 24 small squares of equal size. A unique letter of the alphabet was printed on each small square. Since there were only 24 squares within the…

php 解析mib文件,Mib库解析

MibAnalyser介绍MibAnalyser可以解析MIB文件&#xff0c;并转化为对应的实体&#xff0c;持久化到本地。MibAnalyser分为三个模块&#xff1a;解析模块、持久化模块、工具库模块。解析模块解析模块用于解析MIB文件的语法&#xff0c;并最终生成实体列表。管理模块由于对MIB文件…

【CodeForces - 299C 】Weird Game (思维,模拟,贪心,博弈,OAE思想)

题干&#xff1a; Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesnt show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2n binary characte…

matlab大作业题题单,2011MATLAB大作业-题目-

(1)求解线性规划问题&#xff1a;minZ 4x1 x2 7x3s.t.x1 x2 x3 53x1 x2 x3 4x1 x2 4x3 7x1,x2 0问各xi分别取何值时&#xff0c;Z有何极小值。(2)编写一个函数&#xff0c;使其能够产生如下的分段函数&#xff1a;0.5x&#xff0c;x 2f(x) 1.5 0.25x&#xff0c;2 x 6&#xff…

【CodeForces - 298D】Fish Weight (OAE思想,思维)

题干&#xff1a; It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ …

php 字符串比较的规则,PHP字符串比较函数strcmp()与strcasecmp()的用法介绍

使用“”来判断。它和“”的区别&#xff0c;前者强调“identical(相同的&#xff0c;完全相同)”类型也要求一样&#xff1b;后者要求“equal(相等)”&#xff0c;值相同就可以了。或者使用strcmp来判断&#xff0c;但是这不能说明两个字符串是否相等。一般能用 !, 比较两个对…

【CodeForces - 140C】New Year Snowmen (贪心)

题干&#xff1a; As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergeys twins help him: theyve already made n sno…

php正文重复度,百度如何判断网页文章的重复度?两个页面相似度确认方法介绍...

在这个科技高度发达的时代&#xff0c;百度已经成为人们能获取消息的主要途径。但如今的百度&#xff0c;到处充斥着一些重复的内容&#xff0c;对用户的访问造成很大的困扰。因此&#xff0c;百度需要对网页重复进行判断&#xff0c;对重复的网页&#xff0c;只选取一些高质量…

【CodeForces - 892C 】Pride (数学,思维构造,gcd)

题干&#xff1a; You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the greatest common divisor. What is…

php webshell编写,php webshell学习

一、环境kali 192.168.43.177开户apache /etc/init.d/apache2 start/var/www/html/目录下编辑php代码hackbarhttps://github.com/Mr-xn/hackbar2.1.3二、php基础输出函数:echo - 可以输出一个或多个字符串print - 只允许输出一个字符串&#xff0c;返回值总为 1提示&#xff1a…

【CodeForces - 27E】Number With The Given Amount Of Divisors (数论,数学,反素数)

题干&#xff1a; Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018. Input The first line of the input contains integer n (1 ≤ n ≤ 1000). Outp…

js php c语言for循环,小蚂蚁学习C语言(8)——C语言for循环

最近听到流程控制和循环了&#xff0c;感觉语言之间的语法很相似&#xff0c;不听吧&#xff0c;怕耽误某一个不同点或知识点&#xff0c;听吧&#xff0c;消耗很多时间&#xff0c;着实很纠结&#xff0c;莫非这需要传说中的空杯心态&#xff1f;循环 定义和分类定义&#…

【HDU - 1559】最大子矩阵 (二维前缀和裸题)

题干&#xff1a; 给你一个mn的整数矩阵&#xff0c;在上面找一个xy的子矩阵&#xff0c;使子矩阵中所有元素的和最大。 Input 输入数据的第一行为一个正整数T&#xff0c;表示有T组测试数据。每一组测试数据的第一行为四个正整数m,n,x,y&#xff08;0<m,n<1000 AND 0…

php _invoke 闭包,PHP新特性之闭包、匿名函数

闭包闭包是什么&#xff1f;1).闭包和匿名函数在PHP5.3中被引入。2).闭包是指在创建时封装函数周围状态的函数&#xff0c;即使闭包所在的环境不存在了&#xff0c;闭包封装的状态依然存在&#xff0c;这一点和Javascript的闭包特性很相似。3).匿名函数就是没有名称的函数&…

*【UVA - 10382】Watering Grass(贪心,区间覆盖问题,思维)

题干&#xff1a; 题目大意&#xff1a; 有一块草坪&#xff0c;长为l&#xff0c;宽为w&#xff0c;在它的水平中心线上有n个位置可以安装喷水装置&#xff0c;各个位置上的喷水装置的覆盖范围为以它们自己的半径ri为圆。求出最少需要的喷水装置个数&#xff0c;如果无论如何…

oracle如何把字符集改回默认,更改oracle字符集

在安装oracle时&#xff0c;选了默认字符集是utf8&#xff0c;后来发现与plsql developer工具联合使用时&#xff0c;会出现各种乱码问题。再加上我的项目也是gbk的&#xff0c;因此&#xff0c;将字符集改成gbk试试。步骤如下&#xff1a;1.查看当前的字符集和语言select * fr…

【HDU - 2570】迷瘴 (贪心,水题,排序,卡精度有坑)

题干&#xff1a; 通过悬崖的yifenfei&#xff0c;又面临着幽谷的考验—— 幽谷周围瘴气弥漫&#xff0c;静的可怕&#xff0c;隐约可见地上堆满了骷髅。由于此处长年不见天日&#xff0c;导致空气中布满了毒素&#xff0c;一旦吸入体内&#xff0c;便会全身溃烂而死。 幸好…

oracle 1天后,Oracle Code One - 第1天 精彩亮点回顾

原标题&#xff1a;Oracle Code One - 第1天 精彩亮点回顾原文作者&#xff1a;Padmini Murthy 产品营销总监2018年Oracle CodOracle CodeOne大会实况 – 第1天2018年Oracle CodeOne大会开幕第一天&#xff0c;精彩纷呈&#xff0c;乐趣繁多。从Developers Exchange活动的欢畅交…

【牛客 - 303D第十五届浙江大学宁波理工学院程序设计大赛(同步赛)】Campaign(二进制枚举,位运算,暴力,思维)

题干&#xff1a; 星际争霸(StarCraft)单人战役模式中有很多供人游玩的任务关卡。 tokitsukaze新开始了一关单人战役模式下的任务。在这场战役中&#xff0c;你要作为指挥官指挥克鲁普星区的艾伦人类(Terran)来防御人类的敌人——邪恶异虫(Zerg)的袭击。 这一次&#xff0c;…

oracle mssql 实例,oracle,mysql,SqlServer三种数据库的分页查询的实例

MySql&#xff1a;MySQL数据库实现分页比较简单&#xff0c;提供了 LIMIT函数。一般只需要直接写到sql语句后面就行了。LIMIT子 句可以用来限制由SELECT语句返回过来的数据数量&#xff0c;它有一个或两个参数&#xff0c;如果给出两个参数&#xff0c; 第一个参数指定返回的第…