怎样在一个form里放两个submit按钮,按了以后分别提交到不同的程序

以下两个实例都经过测试,保证能够正常使用。

注意: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>

转载于:https://www.cnblogs.com/cole2295/archive/2009/07/11/1520926.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值