• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >jquery > jQuery搜索框效果实现代码(百度关键词联想)

jQuery搜索框效果实现代码(百度关键词联想)

作者:WuLex 字体:[增加 减小] 来源:互联网

WuLex 通过本文主要向大家介绍了jquery搜索框,关键词联想,jquery搜索关键词等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

可以实现关键词联想的,搜索框;集合了百度,谷歌,搜狗,360,腾讯等多家搜索

search.html的代码:

<!doctype html>
<html>
 <head>
  <title>搜索框例子</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <script type="text/javascript" src="./js/jquery-2.1.3.min.js"></script>

  <script type="text/javascript" src="./js/keyword.js"></script>

  <link href="./css/search.css" rel="stylesheet" type="text/css">
  <style type="text/css">
   *{margin:0 auto}

  </style>
 </head>
 <body>
  <!--start search-->
   <div id="search_bg" style="margin-top:20px;margin-bottom:20px;">
    <div id="button_bg">
     <div class="seach_type">
      <span class="type">站内搜索</span>
      <span class="type">百度搜索</span>
      <span class="type">360搜索</span>
      <span class="type">腾讯搜索</span>
      <span class="type">搜狗搜索</span>
      <span class="type">谷歌搜索</span>
     </div>
     <span class="changetype"></span>
     <form action="http://www.baidu.com/s" method="GET" target="_blank" >
      <input type="text" value="" x-webkit-speech="" lang="zh-CN" placeholder="点击搜索" name="wd" class="textb" autocomplete="off"><!--autocomplete 屏蔽输入自动记录-->
      <input type="submit" name="sub" value="百度一下" class="subb">
     </form>
     <div class="keyword"></div>
    </div>
   </div>
  <!--end start-->
 </body>
</html>

search.css的代码如下:

/*---------------------搜索框样式-------------------------------*/
#search_bg{
 width: 960px;
 height:50px;
}

#search_bg #button_bg .seach_type{
 display: block;
 width: 80px;
 height: auto;
 padding: 0px;
 border: solid 1px rgba(204,204,204,0.5);
 position: absolute;
 top:45px;
 left: 20px;
 display: none;
 z-index: 21;
}
#search_bg #button_bg .seach_type .type{
 display: block;
 width: 80px;
 height: 26px;
 background: rgba(255,255,255,0.3);
 border-bottom:dashed 1px #cccccc;
 text-align: center;
 line-height:26px;
 cursor: pointer;
}
#search_bg #button_bg .seach_type .type:hover{
 color: #126AC1;
}
#search_bg #button_bg .changetype{
 display: block;
 width: 8px;
 height: 12px;
 position: absolute;
 top:20px;
 left: 30px;
 cursor: pointer;
 background: url(../images/class_1_16_1.png);
}
#search_bg #button_bg{
 width:600px;
 height: 50px;

 position: relative;
}
#search_bg #button_bg .textb{
 display: block;
 width: 400px;
 height: 36px;
 outline: none;
 background: none;
 border:solid 1px #CCCCCC;
 float:left;
 margin-top:5px;
 margin-left:20px;
 text-align: left;
 text-indent: 20px;
 font-size: 15px;

}
#search_bg #button_bg .subb{
 display: block;
 width: 80px;
 height: 40px;
 outline: none;
 border: none;
 background: #1F76CB;
 float: left;
 margin-top:5px;
 cursor: pointer;
 box-shadow: 0 1px 2px rgba(28,116,203,0.5);
 color: #ffffff;
 font-size: 15px;
 text-shadow:0 1px 2px rgba(245,247,250,0.2);
}
#search_bg #button_bg .textb:focus{
 border:solid 1px #1F76CB;
}
#search_bg #button_bg .subb:hover{
 box-shadow: 0 1px 3px rgba(28,116,203,1);
}
#search_bg #button_bg .keyword{
 width: 400px;
 height: auto;
 border:solid 1px #cccccc;
 border-top:none;
 position: absolute;
 top:45px;
 left:20px;
 z-index:40;
 box-shadow: 1px 2px 2px rgba(5,5,5,0.1);
 display: none;
}
#search_bg #button_bg .keyword span{
 display: block;
 clear: both;
 width: 400px;
 height: 30px;
 text-indent:15px;
 line-height: 30px;
 cursor: pointer;
 background: rgba(255,255,255,0.3);
 border-bottom:dashed 1px #cccccc;
}
#search_bg #button_bg .keyword span:hover{
 background: rgba(0,0,0,0.5);
}

/*------------------seach结果集样式---------------------*/

#search_result{
width: 960px;
height: auto;
min-height: 400px;
overflow: hidden;
}
#search_result .result_num{
width: 960px;
height: 26px;
text-align: left;
text-indent: 15px;
font-size: 15px;
line-height: 26px;
color:#767676;

}
#search_result .result{
width: 960px;
height: auto;
max-height: 110px;
margin-top:15px;
margin-bottom: 15px;
padding-top: 15px;
padding-bottom: 15px;
text-indent: 20px;
line-height: 25px;
color: #333333;
text-overflow: ellipsis;
overflow: hidden;/*以上三行实现溢出显示省略号*/
border-bottom:dashed 1px #cccccc;
}
#result_page{
 width: 960px;
 height: 30px;
}
#result_page a{
 display: block;
 float: left;
 margin-left:5px;
 width: 30px;
 height: 30px;
 text-align: center;
 text-decoration: none;
 line-height: 30px;
 background: none;
 color: #363636;
 border:solid 1px #A5A5A5;
 transition:all .5s linear;
 -webkit-transition: al.5s linear;/* Safari and Chrome or liebao*/
 -moz-transition: all .5s linear;/*Firefox */
 -o-transition: all .5s linear;/*Opera */
 -ms-transition: all .5s linear;/*for ie*/
}
#result_page a:hover{
 color:#0A67C1;
 border:solid 1px #0A67C1;
}
#result_page .nowpage{
 border:solid 1px #EAE8E8;
 color:#0F9512;
}
#result_page .previous,
#result_page .next{
 width: 80px;
 height: 30px;
}

keyword.js的代码如下:

$(document).ready(function(){
 /*--------------------搜索框样式控制js------------------------*/
 var checktype=$("#search_bg #button_bg .changetype");
 var type=$("#search_bg #button_bg .seach_type .type");
 var seach_type=$("#search_bg #button_bg .seach_type");
 var form=$("#search_bg #button_bg form");
 var textb=$("#search_bg #button_bg form .textb");
 var subb=$("#search_bg #button_bg form .subb");
 var tbcolor="#126AC1";
 textb.focus();//文档加载完毕 搜索框获取焦点
 var search_types={
  "types":[{name:"wd",action:"./search.php",value:"搜索本站",subcolor:"#126AC1",stype:"./images/sanjiao_03.png"},
     {name:"wd",action:"http://www.baidu.com/s",value:"百度一下",subcolor:"#126AC1",stype:"./images/sanjiao_03.png"},
     {name:"q",action:"http://www.so.com/s",value:"360搜索",subcolor:"#53C920",stype:"./images/sanjiao_04.png"},
     {name:"w",action:"http://www.soso.com/q",value:"腾讯搜索",subcolor:"#760AAA",stype:"./images/sanjiao_05.png"},
     {name:"query",action:"http://www.xuan369.com/so/qqkk8.jsp",value:"搜狗搜索",subcolor:"#F94F1B",stype:"./images/sanjiao_06.png"},
     {name:"q",action:"http://209.85.228.42/search",value:"谷歌搜索",subcolor:"#29C971",stype:"./images/sanjiao_07.png"}
    ]};
 //alert(search_types.types[1].value);
 //选择搜索类型按钮被点击
 checktype.click(function(){
  seach_type.css({"display":"block",height:0});
  seach_type.animate({
   height:(type.height()+1)*type.length,
  },500);

 });

 type.click(function(){
  //alert(search_types.types[$(this).index()].value)
  form.attr("action",search_types.types[$(this).index()].action);//改变表单提交位置
  textb.attr("name",search_types.types[$(this).index()].name);//改变表单变量名
  subb.val(search_types.types[$(this).index()].value);//改变按钮显示
  subb.css({background:search_types.types[$(this).index()].subcolor});//改变按钮颜色
  tbcolor=search_types.types[$(this).index()].subcolor;//改变输入框边框颜色
  checktype.css({"background":"url("+search_types.types[$(this).index()].stype+")"});
  subb.css({"box-shadow":"0 1px 2px "+search_types.types[$(this).index()].subcolor});
  textb.focus();//编辑框获取焦点
  seach_type.animate({
   height:0,
  },500,function(){
   seach_type.css({"display":"none",height:0});
  });
 });

 seach_type.mouseleave(function(){
  seach_type.animate({
   height:0,
  },500,function(){
   seach_type.css({"display":"none",height:0});
  });
 });
 textb.focus(function(){
  textb.css({border:"solid 1px "+tbcolor});
  //
  seach_type.animat



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • jQuery搜索框效果实现代码(百度关键词联想)
  • jQuery实现的类似淘宝网站搜索框样式代码分享

相关文章

  • 基于jQuery实现滚动刷新效果
  • jQuery中的.bind()、.live()和.delegate()之间区别分析
  • JavaScript获取onclick、onchange等事件值的代码
  • Jquery zTree 树控件异步加载操作
  • jQuery表单验证插件formValidator(改进版)
  • jQuery插件Elastislide实现响应式的焦点图无缝滚动切换特效
  • 扩展jquery easyui tree的搜索树节点方法(推荐)
  • 如何让你的Lightbox支持滚轮缩放及Base64图片
  • jquery 表单验证之通过 class验证表单不为空
  • 浅析jQuery Mobile的初始化事件

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • js jquery做的图片连续滚动代码
    • jQuery的each终止或跳过示例代码
    • 用jquery实现点击栏目背景色改变
    • jquery中表单 多选框的一种巧妙写法
    • jQuery插件imgPreviewQs实现上传图片预览
    • 基于jquery实现日历签到功能
    • jQuery向后台传入json格式数据的方法
    • 浅谈jquery中delegate()与live()
    • jQuery的内容过滤选择器学习教程
    • Jquery插件实现点击获取验证码后60秒内禁止重新获取

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有