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

2019-12-18,,,,,

本文实例讲述了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程序设计有所帮助。

您可能感兴趣的文章:

  • JS+CSS实现仿新浪微博搜索框的方法
  • JS实现关键字搜索时的相关下拉字段效果
  • JS使用replace()方法和正则表达式进行字符串的搜索与替换实例
  • JS仿百度搜索自动提示框匹配查询功能
  • 用JS将搜索的关键字高亮显示实现代码
  • js实现带搜索功能的下拉框实时搜索实时匹配
  • JS性能优化笔记搜索整理
  • 利用PHP+JS实现搜索自动提示(实例)
  • JS实现表格数据各种搜索功能的方法

《JS实现同时搜索百度和必应的方法.doc》

下载本文的Word格式文档,以方便收藏与打印。