<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
*{ margin:; padding:; list-style:none;}
#box{ width:645px; margin:10px auto; text-align:center; overflow:hidden; font-size:20px;}
#box img{ width:270px; height:129px;}
#t1{ width:540px; height:36px; line-height:36px; outline:none; text-indent:6px; font-size:20px;}
.s_btn {
outline:none;
width: 100px;
height: 40px;
float:right;
color: rgb(, , );
font-size: 15px;
letter-spacing: 1px;
background: rgb(, , );
border-bottom: 1px solid rgb(, , );
-webkit-appearance: none;
border:none;
-webkit-border-radius: ;
margin-left:1px;
cursor:pointer;
}
#box ul{ width:542px; border:1px solid #ccc; border-top:none; text-align:left; text-indent:6px; display:none;}
#box ul li{ height:30px; line-height:30px; cursor:default;}
#box ul li.on{ background:#f0f0f0;}
</style>
<script src="jquery-1.7.2.js"></script>
<script>
$(function(){
var oBox=$('#box');
var oBtn=$('#btn1');
var oTxt=$('#t1');
var oUl=$('#ul1');
var iNow=-;
var oldValue='';
var url='https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su';
oTxt.on('keyup',function(ev){
if(ev.keyCode==||ev.keyCode==){
return;
}
if(ev.keyCode==){
window.open('https://www.baidu.com/s?wd='+oTxt.val(),'_self');
oTxt.val('');
}
$.ajax({
url:url,
data:{
wd:oTxt.val()
},
dataType:'jsonp',
jsonp:'cb',
timeout:,
success:function(json){
var arr=json.s;
if(arr.length){
oUl.css('display','block');
}else{
oUl.css('display','none');
}
oUl.html('');
$.each(arr,function(index){
var oLi=document.createElement('li');
$(oLi).html(arr[index]);
$(oLi).appendTo(oUl);
$(oLi).on('mouseover',function(){
$.each(oUl.children(),function(t){
oUl.children().eq(t).removeClass('on');
});
$(this).addClass('on');
});
$(oLi).on('mouseout',function(){
$.each(oUl.children(),function(t){
oUl.children().eq(t).removeClass('on');
});
});
$(oLi).on('click',function(){
window.open('https://www.baidu.com/s?wd='+$(this).html(),'_self');
oTxt.val('');
});
});
},
error:function(){
alert('网络异常,请重新输入');
}
});
oldValue=oTxt.val();
});
oBtn.on('click',function(){
window.open('https://www.baidu.com/s?wd='+oTxt.val(),'_self');
oTxt.val('');
});
oTxt.on('keydown',function(ev){
var aLi=$('li');
switch(ev.keyCode){
case :
iNow++;
if(iNow==aLi.length){iNow=-};
$.each(aLi,function(index){
aLi.eq(index).removeClass('on');
});
if(iNow==-){
oTxt.val(oldValue);
}else{
aLi.eq(iNow).addClass('on');
oTxt.val(aLi.eq(iNow).html());
}
break;
case :
iNow--;
if(iNow==-){iNow=aLi.length-};
$.each(aLi,function(index){
aLi.eq(index).removeClass('on');
});
if(iNow==-){
oTxt.val(oldValue);
}else{
aLi.eq(iNow).addClass('on');
oTxt.val(aLi.eq(iNow).html());
}
break;
}
});
});
</script>
</head> <body>
<div id="box">
<img src="https://www.baidu.com/img/bd_logo1.png"><br>
<input type="text" id="t1"><input type="submit" id="btn1" value="百度一下" class="bg s_btn">
<ul id="ul1">
<!--<li class="on"></li>-->
<!--<li></li>-->
<!--<li></li>-->
<!--<li></li>-->
</ul>
</div>
</body>
</html>

百度搜索--jquery的更多相关文章

  1. js/jQuery实现类似百度搜索功能

    一.页面代码:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...

  2. jsonp模拟获取百度搜索相关词汇

    随便写了个jsonp模拟百度搜索相关词汇的小demo,帮助新手理解jsonp的用法. <!DOCTYPE html><html lang="en">< ...

  3. 仿百度搜索(AJAX)

    <h1>百度搜索</h1><!--建立一个DIV,其中包括一个文本输入框和一个按钮--><div id="sousuo"> < ...

  4. JavaScript实现模糊推荐的input框(类似百度搜索框)

    如何用JS实现一个类似百度搜索框的输入框呢,再填充完失去焦点时,自动填充配置项,最终效果如下图: 实现很简单,但是易用性会上升一大截,需要用到的有jquery-ui的autocomplete,jque ...

  5. 教你编写百度搜索广告过滤的chrome插件

    1 前言 目前百度搜索列表首页里,广告5条正常内容是10条,而且广告都是前1到5条的位置,与正常内容的显示样式无异.对于我们这样有能力的开发者,其实可以简单的实现一个chrome插件,在百度搜索页面里 ...

  6. Ruby用百度搜索爬虫

    Ruby用百度搜索爬虫 博主ruby学得断断续续,打算写一个有点用的小程序娱乐一下,打算用ruby通过百度通道爬取网络信息. 第三方库准备 mechanize:比较方便地处理网络请求,类似于Pytho ...

  7. 使用Tampermonkey(油猴) 插件,重新实现了,百度搜索热点过滤功能

    昨天晚上,花了点时间学习了Chrome插件的制作方法,并书写了<Chrome 百度搜索热点过滤插件 - 开源软件>这一文章,简单地介绍自己实现的百度搜索热点过滤神器的原理和使用方式,并进行 ...

  8. 利用autocomplete.js实现仿百度搜索效果(ajax动态获取后端[C#]数据)

    实现功能描述: 1.实现搜索框的智能提示 2.第二次浏览器缓存结果 3.实现仿百度搜索 <!DOCTYPE html> <html xmlns="http://www.w3 ...

  9. 原生js 定义分页控件,类似于百度搜索

    实现一个类似于百度搜索结果的分页样式,样式可以自定义,接近于原生,少部分Jquery . 1.实现效果截图(默认无任何样式)  2.主要程序代码 define(function (require, e ...

随机推荐

  1. 定时从多个Excel导入数据到SQL数据库

    Scheduling Data Imports in SQL Server Importing data into a SQL Server database isn't really that tr ...

  2. 腾讯bugly 的crash 上报和umeng的比较

    说到crash上传工具,大家肯定会第一时间想到umeng,不错,umeng 是最早推出 crash 上报的工具之一,在刚推出来的时候,特别受到ios开发人员的喜爱. 因为个时候,内存是手动管理的,很容 ...

  3. 根据字符串生成类---类的类型.self---根据字符串创建控制器对象

    swift和OC一样,都是通过NSClassFromString,根据一个字符串,生成相应的类. // UITabBarButton是系统的私有类,不能直接使用 // if btn.isKind(of ...

  4. Android根据字符串加载Activity和图片

    根据传入的字符串跳转Activity Intent intent = new Intent(context,Class.forName("com.packname.Activity" ...

  5. ios 图片的两种加载方式

    控件加载图片,plist,懒加载,序列帧动画,添加动画效果. IOS中有2种加载图片的方式. 方式一:有缓存(图片所占用的内存会一直停留在程序中) + (UIImage *)imageNamed:(N ...

  6. iOS 学习 - 4.存储聊天记录

    主要是用sqlite3来存储聊天记录 先导入sqlite3.dylib, 点 Add Other,同时按住shift+command+G, 在弹出的Go to the folder中输入/usr/li ...

  7. MySQL开启慢查询 总结

    MYSQL慢查询配置 1. 慢查询有什么用? 它能记录下所有执行超过long_query_time时间的SQL语句, 帮你找到执行慢的SQL, 方便我们对这些SQL进行优化. 2. 如何开启慢查询? ...

  8. VS2013崩溃,无法打开项目的解决方案

    最近遇到VS2013,在打开解决方案时,报如下错误: “未找到与约束 ContractName Microsoft.Internal.VisualStudio.PlatformUI.ISolution ...

  9. ORACLE数据库的限制

    ORACLE数据库最多可以拥有多少个表空间(Tablespace)?数据库最多拥有多少个数据文件(Database files).数据库的数据文件最大可以多大?遇到这些问题只能查询官方文档,人的记忆能 ...

  10. [Linux 维护]收集centos系统性能指标

    #!/bin/bash # awk 'END{print}' get the last row iplist=$(cat ~/fanr/shell/Weekly/ip.list) for _IP in ...