當前位置:軟件學堂 > 資訊首頁 > 網絡編程 > 編程其他 > 如何設計綜合的搜索引擎

如何設計綜合的搜索引擎

2012/10/26 12:13:04作者:佚名來源:網絡

移動端

【實例名稱】

綜合的搜索引擎

【實例描述】

搜索是獲取網絡信息的重要方法。本例通過一個簡單的頁面,學習如何整合多個搜索引擎為自己所用。

【實例代碼】

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>標題頁-學無憂(www.yzddtk.cn)</title>
</head>
<body>
<form Name="InputForm">
<div align="center"><center><p>
<script language="JavaScript">
var FirstForm;
function StartSearch()
{
//使用隱藏控件保存用戶輸入的查詢參數
document.forms[FirstForm+document.InputForm.SearchSelect.
selectedIndex].elements[0].value=document.InputForm.SearchWords.value;
//提交查詢參數到指定網站
document.forms[FirstForm+document.InputForm.SearchSelect.selectedIndex].submit();
}
</script>
<span style="font-size: 9pt">查找內容:</span>
<input name="SearchWords" type="text" size="21" style=" margin-left: 1px"><br>
<span style="font-size: 9pt">搜索引擎:</span>
<select Name="SearchSelect" size="1" >
<option selected>英文Yahoo</option>
<option value="Google搜索">中文Google</option>
<option value="百度搜索">百度中文搜索</option>
</select><br>
<input type="button" value=" 開始查找 " onClick="StartSearch()"> 
<script language="JavaScript">
FirstForm=document.forms.length
</script></p>
</center></div>
</form>
<form action="http://search.yahoo.com/bin/search" method="get">
<input type="hidden" name="p" value>
</form>
<form action="http://www.google.com/search">
<input type="hidden" name="q" value>
</form>
<form action="http://www.baidu.com/s">
<input type="hidden" name="wd" value>
</form>
</body>
</html>

【運行效果】

                                                  搜索引擎的運行效果

運行效果

                                                          搜索結果

運行效果

注意其地址欄的搜索參數,如果搜索內容為中文,則會被編碼化。

【難點剖析】

本例的重點是在頁面中添加多個form,然后使用form的“action”方法提交當前頁面到搜索頁面。在提交時要注意修改搜索參數,因為不同的搜索引擎,其搜索參數不同。如本例中google的搜索參數為“q”,百度的搜索參數為“wd”。

【源碼下載】

本實例JS代碼下載

 

標簽: 下拉框    

欧美一级一极性活片免费观看,欧美一级艳片欧美精品,欧美一级性爱大片,欧美一级囗交视频 视频,欧美一级特黄录像视频