以下两个实例都经过测试,保证能够正常使用。
注意:google站内搜索代码中method="get",本文全部采用了get方式提交。也可以在js代码中对提交方式进行处理(实例略)。
实例一:
<script language="javascript">
function chkForm(frm)
{
if (frm.q.value=="" || frm.q.value==" -- 关键词搜索 -- ")
{
alert("请输入您要查询的关键字!");
frm.q.focus();
return false;
}
}
function clearInput(thisInput)
{
if (thisInput.value==' -- 关键词搜索 -- ')
{
thisInput.value='';
}
}
function doSubmit(i)
{
switch (i)
{
case 1:
searchForm.action="search.asp";//(此处自己改)
break;
case 2:
searchForm.action="http://www.google.com/search";//(此处自己改)
}
}
</script>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="196" height="30" align="center" background="images/index_61.jpg" class="title2">站内搜索</td>
</tr>
<tr>
<td height="4"></td>
</tr>
<form action="" method="get" onSubmit="return chkForm(this)" name="searchForm">
<input type="hidden" name="domains" value="www.8848ol.com">
<input type="hidden" name="sitesearch" value="www.8848ol.com">
<input type="hidden" name="ie" value="GB2312">
<input type="hidden" name="oe" value="GB2312">
<input type="hidden" name="hl" value="zh-CN">
<tr>
<td height="95"><table width="150" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="28" colspan="2" align="center"><select name="schType" id="schType" style="width:138px">
<option value="0"> -- 标题搜索 -- </option>
<option value="1"> -- 全文搜索 -- </option>
</select></td>
</tr>
<tr>
<td height="28" colspan="2" align="center"><input type="text" name="q" value=" -- 关键词搜索 -- " onFocus="clearInput(this)" style="width:138px"/></td>
</tr>
<tr>
<td height="30" align="center"><input type="image" src="images/index_51.jpg" width="22" height="22" border="0" onClick="javascript:doSubmit(1)"/>
</a></td>
<td height="30" align="center"><input type="image" src="images/index_47.jpg" width="112" height="24" border="0" onClick="javascript:doSubmit(2)"/></td>
</tr>
</table></td>
</tr>
</form>
</table>
实例二:
<script language="javascript">
function chkForm(frm)
{
if (frm.q.value=="" || frm.q.value==" -- 关键词搜索 -- ")
{
alert("请输入您要查询的关键字!");
frm.q.focus();
return false;
}
}
function clearInput(thisInput)
{
if (thisInput.value==' -- 关键词搜索 -- ')
{
thisInput.value='';
}
}
function frmSubmit1(frm){
frm.action = "search.asp";
}
function frmSubmit2(frm){
frm.action = "http://www.google.com/search";
}
</script>
<table width="532" border="0" align="center" cellpadding="0" cellspacing="0">
<form action="" method="get" onSubmit="return chkForm(this)">
<input type="hidden" name="domains" value="www.8848ol.com">
<input type="hidden" name="sitesearch" value="www.8848ol.com">
<input type="hidden" name="ie" value="GB2312">
<input type="hidden" name="oe" value="GB2312">
<input type="hidden" name="hl" value="zh-CN">
<tr>
<td width="105"><img src="images/index_49.jpg" width="93" height="20" /></td>
<td width="135"><input type="text" name="q" value=" -- 关键词搜索 -- " onFocus="clearInput(this)" style="width:130px"/></td>
<td width="115"><select name="schType" id="schType" style="width:90px">
<option value="0">标题搜索</option>
<option value="1">全文搜索</option>
</select></td>
<td width="41"><input type="image" src="images/index_51.jpg" width="22" height="22" border="0" onClick="frmSubmit1(this.form)"/></td>
<td width="136"><input type="image" src="images/index_46.jpg" width="134" height="24" border="0" onClick="frmSubmit2(this.form)"/></td>
</tr>
</form>
</table>