JavaScript切换搜索引擎的导航网页搜索框实例代码


Posted in Javascript onJune 11, 2017

废话不多说了,直接给大家贴代码了,具体代码如下所述:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <style>
    #search ul {
      list-style-type: none;
      display: block;
      width: 100px;
      height: 33px;
      margin: 0;
      padding: 0;
      border: 0px;
      float: left;
    }
    #search li {
      border: 0px;
      margin: 0px;
      padding: 0px;
    }
    #search .selected {
      display: block;
    }
    #search form {
      margin: 0px;
      padding: 0px;
    }
    #search input {
      height: 30px;
      width: 400px;
      margin: 0px;
    }
    #search .button {
      font-size: 17px;
      font-weight: 600;
      color: #002D96;
      height: 30px;
      width: 110px;
      margin-left: 50px;
      background: #e6efc2;
      opacity: 0.8;
      border: #7fb80e 1px solid;
      cursor: pointer;
      -webkit-border-radius: 2px;
      border-radius: 2px;
    }
  </style>
</head>
<body>
<div id="search" align="center">
  <table>
    <tr>
      <td>
        <ul>
          <li style="display:block;"><img width="80" src="https://www.baidu.com/img/bd_logo1.png"/></li>
          <li style="display:none;"><img width="80" src="https://www.google.com.hk/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png"/></li>
          <li style="display:none;"><img width="80" src="https://www.sogou.com/images/logo2014/error180x60.png"/></li>
        </ul>
      </td>
      <td id="from_box" style="padding-left:10px;">
        <form id="from_baidu" style="display:block" action="http://www.baidu.com/baidu" target="_blank" method="get">
          <input name="" type="hidden" value="baidu"/>
          <input type="text" name="word"/>
          <input class="button" type="submit" value="百度一下" onMouseOver="this.style.opacity='1'" onMouseOut="this.style.opacity='0.7'"/>
        </form>
        <form id="from_google" style="display:none" action="http://www.google.com/search" target="_blank" method="get">
          <input type="text" name="q"/>
          <input class="button" type="submit" value="google搜索" onMouseOver="this.style.opacity='1'" onMouseOut="this.style.opacity='0.7'"/>
        </form>
        <form id="from_sougou" style="display:none" action="http://www.sogou.com/web" target="_blank" name="sogou_queryform">
          <input type="text" name="query">
          <input class="button" type="submit" value="sougou搜索" onMouseOver="this.style.opacity='1'" onMouseOut="this.style.opacity='0.7'"/>
        </form>
      </td>
    </tr>
  </table>
</div>
<script>
  var search = document.getElementById("search");
  var formbox = document.getElementById('from_box');
  var forms = formbox.getElementsByTagName("form");
  var ul = search.getElementsByTagName("ul")[0];
  var li = ul.getElementsByTagName("li");
  var length = li.length;
  li[0].onclick = function() {
    for(var i = 1; i < length; i++) {
      li[i].style.display = "block";
    }
  }
  var n = 0; //第一个显示表单的位置
  for(var i = 1; i < length; i++) {
    li[i].onclick = function(a) {
      return function() {
        //交换显示的html内容
        var temp = li[0].innerHTML;
        li[0].innerHTML = this.innerHTML;
        this.innerHTML = temp;
        for(var j = 1; j < length; j++) {
          li[j].style.display ="none";
        }
        //交换表单的显示
        //alert(li[0].innerHTML.substring(37,7));
        //alert(li[0].innerHTML.indexOf('baidu'));
        hidden_from(); //隐藏表单
        if(li[0].innerHTML.indexOf('baidu') > 0) {
          document.getElementById('from_baidu').style.display = 'block';
        } else if(li[0].innerHTML.indexOf('google') > 0) {
          document.getElementById('from_google').style.display = 'block';
        } else if(li[0].innerHTML.indexOf('sougou') > 0) {
          document.getElementById('from_sougou').style.display = 'block';
        }
        //alert(this.innerHTML);
        //forms[n].style.display = "none";
        //forms[a].style.display = "block";
        //n = a;
      }
    }(i);
    li[i].onmouseover = function() {
      this.style.border ="#7fb80e 1px solid";
      this.style.background ="#f2eada";
    }
    li[i].onmouseout = function() {
      this.style.border = "0px";
      this.style.background = "inherit";
    }
  }
  //隐藏搜索框表单的函数
  function hidden_from() {
    for(var j = 0; j < forms.length; j++) {
      forms[j].style.display = "none";
    }
  }
</script>
</body>
</html>

以上所述是小编给大家介绍的JavaScript切换搜索引擎的导航网页搜索框实例代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

Javascript 相关文章推荐
node.js中的events.emitter.listeners方法使用说明
Dec 10 Javascript
浅谈window对象的scrollBy()方法
Jul 15 Javascript
easyui中combotree循环获取父节点至根节点并输出路径实现方法
Nov 10 Javascript
AngularJS自定义服务与fliter的混合使用
Nov 24 Javascript
微信小程序基于本地缓存实现点赞功能的方法
Dec 18 Javascript
详解vue-cli之webpack3构建全面提速优化
Dec 25 Javascript
JavaScript设计模式之建造者模式实例教程
Jul 02 Javascript
老生常谈JS中的继承及实现代码
Jul 06 Javascript
Vue插件从封装到发布的完整步骤记录
Feb 28 Javascript
no-vnc和node.js实现web远程桌面的完整步骤
Aug 11 Javascript
Vuex模块化应用实践示例
Feb 03 Javascript
Vue双向绑定实现原理与方法详解
May 07 Javascript
jQuery复合事件结合toggle()方法的用法示例
Jun 10 #jQuery
jQuery复合事件用法示例
Jun 10 #jQuery
jQuery简单绑定单个事件的方法示例
Jun 10 #jQuery
jQuery正则验证注册页面经典实例
Jun 10 #jQuery
详解Angular4中路由Router类的跳转navigate
Jun 09 #Javascript
基于vue2.0实现的级联选择器
Jun 09 #Javascript
JavaScript设计模式之代理模式详解
Jun 09 #Javascript
You might like
老机欣赏|中国60年代精品收音机
2021/03/02 无线电
php中取得文件的后缀名?
2012/02/20 PHP
android上传图片到PHP的过程详解
2015/08/03 PHP
thinkPHP框架实现的短信接口验证码功能示例
2018/06/20 PHP
Nigma vs Liquid BO3 第一场2.13
2021/03/10 DOTA
js 刷新页面的代码小结 推荐
2010/04/02 Javascript
JavaScript中关于indexOf的使用方法与问题小结
2010/08/05 Javascript
为你的网站增加亮点的9款jQuery插件推荐
2011/05/03 Javascript
JS预览图像将本地图片显示到浏览器上
2013/08/25 Javascript
jquery ready函数、css函数及text()使用示例
2013/09/27 Javascript
微信小程序 视图层(xx.xml)和逻辑层(xx.js)详细介绍
2016/10/13 Javascript
html中鼠标滚轮事件onmousewheel的处理方法
2016/11/11 Javascript
jQuery如何跳转到另一个网页 就这么简单
2016/12/28 Javascript
JavaScript中匿名函数的递归调用
2017/01/22 Javascript
bootstrap suggest搜索建议插件使用详解
2017/03/25 Javascript
微信小程序分页加载的实例代码
2017/07/11 Javascript
10个最优秀的Node.js MVC框架
2017/08/24 Javascript
通过一个简单的例子学会vuex与模块化
2017/11/22 Javascript
JS随机密码生成算法
2019/09/23 Javascript
jQuery实现日历效果
2020/09/11 jQuery
[53:15]Mineski vs iG 2018国际邀请赛小组赛BO2 第二场 8.16
2018/08/17 DOTA
python实现simhash算法实例
2014/04/25 Python
用Python程序抓取网页的HTML信息的一个小实例
2015/05/02 Python
使用pandas实现csv/excel sheet互相转换的方法
2018/12/10 Python
python实现Dijkstra静态寻路算法
2019/01/17 Python
Python查找最长不包含重复字符的子字符串算法示例
2019/02/13 Python
打印tensorflow恢复模型中所有变量与操作节点方式
2020/05/26 Python
详解css3中的伪类before和after常见用法
2020/11/17 HTML / CSS
使用 HTML5 Canvas 制作水波纹效果点击图片就会触发
2014/09/15 HTML / CSS
亚洲航空公司官方网站:AirAsia
2019/11/25 全球购物
大专应届生个人的自我评价
2013/11/21 职场文书
社区志愿者心得体会
2014/01/03 职场文书
应届毕业生简历自我评价
2014/01/31 职场文书
朋友聚会开场白
2015/06/01 职场文书
护士心得体会范文
2016/01/25 职场文书
td 内容自动换行 table表格td设置宽度后文字太多自动换行
2022/12/24 HTML / CSS