<!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. GitHub使用指南

    文章地址:http://www.worldhello.net/gotgithub/index.html

  2. Ioc Autofac心得

    对于这个容器注入,个人也不是很熟悉,很多还不懂,只会基本的操作,几天把它记录下来,说不定以后帮助就大了呢,这方面跟安卓差距还是挺大的 下面记录下应用的流程 步骤: 1.添加应用 2.重写工厂(这里讲的 ...

  3. 2016春招Android开发实习生(网易传媒)笔试

    一.单选题 1.下列不属于网络层协议的为 TCP IP IPX ICMP 2.关于activity的状态恢复,错误的是 onSaveInstanceState中,activity会自动收集恢复view ...

  4. 阿里云服务器怎么去掉tomcat的8080端口

    前言:最近在阿里云申请了一个云服务器,然后已买了一个域名.比如www.haha.com ; 在云服务器上安装了tomcat ,访问服务器就成了 http://www.haha.com:8080/ . ...

  5. android中实现跑马灯效果以及AutoCompleteTestView与MultiAutoCompleteTextView的学习

    跑马灯效果 1.用过属性的方式实现跑马灯效果 属性:                  android:singleLine="true" 这个属性是设置TextView文本中文字 ...

  6. iOS如何获取网络图片(三)有沙盒的

    沙盒 沙盒简介 默认情况下,每个沙盒含有3个文件夹:Documents, Library 和 tmp.因为应用的沙盒机制,应用只能在几个目录下读写文件 Documents:苹果建议将程序中建立的或在程 ...

  7. AutoLayout自动布局

      原文转自http://www.cnblogs.com/xjf125/p/4895978.html 目录: 一.什么是AutoLayout? 二.创建autoLayout的方法 三.VFL语言   ...

  8. CodeForce Round#49 untitled (Hdu 5339)

    Untitled Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  9. Xshell与securecrt之间不同

    现在比较受欢迎的终端模拟器软件当属xshell和securecrt了,现在就客观的分析一下两款软件,以便更好选择. 一.功能对比1.1Xshell功能 支持布局切换 可调整执行顺序 提供多标签功能 对 ...

  10. Mysql Error:1205错误诊断

    前两天遇到一个1205(ER_LOCK_WAIT_TIMEOUT)的错误,弄了半天终于找到原因,掌握原理+细心才能找到罪归祸首.下面我给大家分享下这个问题的分析处理过程,希望对大家有所帮助.接到sla ...