JS实现同时搜索百度和必应的方法

  本文实例讲述了JS实现同时搜索百度和必应的方法。分享给大家供大家参考。具体如下:

  这里实现同时搜索百度和必应的功能,输入关键字,点击“搜一下”按钮,两个搜索引擎的结果在同个页面打开,方便。

  将下面这两个htm文件保存,放在同一个文件夹下,打开第一个文件就可以了。

  index.htm的代码:

  

复制代码 代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

  <html>

  <head>

  <meta http-equiv="content-type" content="text/html; charset=UTF-8">

  <title>同时搜索百度和必应</title>

  <meta http-equiv="keywords" content="同时搜索百度和必应">

  <meta http-equiv="description" content="同时搜索百度和必应">

  </head>

  <!--<body style="text-align: center;">

  -->

  <frameset rows="30%,70%">

  <frame src="keleyi.htm">

  </frame>

  <frameset cols="45%,45%">

  <frame id="baiduFrame" name="baiduFrame" src="images/baidu.jpg"></frame>

  <frame id="bingFrame" name="bingFrame" src="images/baidu.jpg"></frame>

  </frameset>

  </frameset>

  <!--<iframe id="baiduFrame" width="49%" height="100%" ></iframe>

  <iframe id="bingFrame" width="49%" height="100%" ></iframe>

  </body>-->

  </html>

  第二个的文件名为keleyi.htm

  keleyi.htm的代码如下:

  

复制代码 代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

  <html>

  <head>

  <meta http-equiv="content-type" content="text/html; charset=UTF-8">

  <title>同时搜索百度和必应</title>

  <meta http-equiv="keywords" content="同时搜索百度和必应">

  <meta http-equiv="description" content="同时搜索百度和必应">

  <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  <script type="text/javascript">

  function $(id) {

  return document.getElementById(id);

  }

  function mixSearch() {

  var okeyword = $("keyword");

  var oForm = $("searchForm");

  //提交给百度,构造地址参数

  oForm.action = "http://www.baidu.com/s";

  okeyword.name = "wd";

  oForm.method = "get";

  oForm.target = "baiduFrame";

  oForm.submit();

  //提交给bing,构造地址参数

  oForm.action = "http://hk.bing.com/search";

  okeyword.name = "q";

  oForm.method = "get";

  oForm.target = "bingFrame";

  oForm.submit();

  }

  </script>

  </head>

  <body style="text-align: center;">

  <form action="" id="searchForm" method="get" target="baiduFrame">

  <input type="text" id="keyword" name="wd" value="" />

  <input type="button" value="搜一下~" onclick="mixSearch();" />

  </form>

  <hr />

  </body>

  </html>

  希望本文所述对大家的javascript程序设计有所帮助。