百度搜索--jquery
<!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的更多相关文章
- js/jQuery实现类似百度搜索功能
一.页面代码:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...
- jsonp模拟获取百度搜索相关词汇
随便写了个jsonp模拟百度搜索相关词汇的小demo,帮助新手理解jsonp的用法. <!DOCTYPE html><html lang="en">< ...
- 仿百度搜索(AJAX)
<h1>百度搜索</h1><!--建立一个DIV,其中包括一个文本输入框和一个按钮--><div id="sousuo"> < ...
- JavaScript实现模糊推荐的input框(类似百度搜索框)
如何用JS实现一个类似百度搜索框的输入框呢,再填充完失去焦点时,自动填充配置项,最终效果如下图: 实现很简单,但是易用性会上升一大截,需要用到的有jquery-ui的autocomplete,jque ...
- 教你编写百度搜索广告过滤的chrome插件
1 前言 目前百度搜索列表首页里,广告5条正常内容是10条,而且广告都是前1到5条的位置,与正常内容的显示样式无异.对于我们这样有能力的开发者,其实可以简单的实现一个chrome插件,在百度搜索页面里 ...
- Ruby用百度搜索爬虫
Ruby用百度搜索爬虫 博主ruby学得断断续续,打算写一个有点用的小程序娱乐一下,打算用ruby通过百度通道爬取网络信息. 第三方库准备 mechanize:比较方便地处理网络请求,类似于Pytho ...
- 使用Tampermonkey(油猴) 插件,重新实现了,百度搜索热点过滤功能
昨天晚上,花了点时间学习了Chrome插件的制作方法,并书写了<Chrome 百度搜索热点过滤插件 - 开源软件>这一文章,简单地介绍自己实现的百度搜索热点过滤神器的原理和使用方式,并进行 ...
- 利用autocomplete.js实现仿百度搜索效果(ajax动态获取后端[C#]数据)
实现功能描述: 1.实现搜索框的智能提示 2.第二次浏览器缓存结果 3.实现仿百度搜索 <!DOCTYPE html> <html xmlns="http://www.w3 ...
- 原生js 定义分页控件,类似于百度搜索
实现一个类似于百度搜索结果的分页样式,样式可以自定义,接近于原生,少部分Jquery . 1.实现效果截图(默认无任何样式) 2.主要程序代码 define(function (require, e ...
随机推荐
- '[<NSObject 0x8a4b500> setValue:forUndefinedKey:]
Bug如下: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUnd ...
- 【代码笔记】iOS-给背景图赋值颜色
代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // ...
- 【原+转】用CMake代替makefile进行跨平台交叉编译
在开始介绍如何使用CMake编译跨平台的静态库之前,先讲讲我在没有使用CMake之前所趟过的坑.因为很多开源的程序,比如png,都是自带编译脚本的.我们可以使用下列脚本来进行编译: ./configu ...
- push notification获取device token
第一步:申请证书: 第二步:申请app ids,应用名字必须一致.然后再进入进行编辑,使其enable,绿灯. 第三步:申请provisioning profile,生成.mobileprovisio ...
- raw_input() 与 input() __ Python
这两个均是 python 的内建函数,通过读取控制台的输入与用户实现交互.但他们的功能不尽相同.举两个小例子. 1 >>> raw_input_A = raw_input(" ...
- css文本格式详解
一.css文本主体内容: 二.css文本详解: 1.文本缩进 语法: text-indent:<length>|<percentage> 默认值为0. 属性值详解: < ...
- 开始对函数式编程 产生了尊崇感,因为Spring4.x ,Grooxy,Lisp,网易出来伞哥和他的博客
1 无意看到"丢弃重口味的xml配置--spring4用groovy配置bean",这篇文章,里面说到spring4开始可以使用Groovy进行配置,可以取代xml方式和注解方式 ...
- openstack security group and rules python api use
nova和neutron都可以,但是感觉还是用neutron好. import neutronclient.v2_0.client as neclient neutron = neclient.Cli ...
- SQL Server:统计数据库中每张表的大小
1. 统计数据库中每张表的大小 1.1 首先执行下面的命令 exec sp_MSforeachtable @command1="sp_spaceused '?'"; 1.2 检测当 ...
- 记一次MongoDB Map&Reduce入门操作
需求说明 用Map&Reduce计算几个班级中,每个班级10岁和20岁之间学生的数量: 需求分析 学生表的字段: db.students.insert({classid:1, age:14, ...