本文参考:http://my.oschina.net/sallency/blog/300568

在开发工作共我们往往会遇到一个表单需要包含多个action不同的提交动作,这时候就不能在使用submit按钮来进行提交了,下面提供通过js来实现这一功能的方法.

示例代码:

<form name="demo" method="post">
<!--YOUR DATA AREA-->
<input type="button" value="添加" onclick="addAction()">
<input type="button" value="删除" onclick="deleteAction()">
<input type="button" value="保存" onclick="saveAction()">
<input type="button" value="查询" onclick="searchAction()">
</form> <script type="text/javascript">
function addAction(){
document.demo.action="your add method url";
document.demo.submit();
} function deleteAction(){
document.demo.action="your delete method url";
document.demo.submit();
} function saveAction(){
document.demo.action="your add save url";
document.demo.submit();
} function searchAction(){
document.demo.action="your serach method url";
document.demo.submit();
}
</script>

//==================

demo中的代码(JSP中的hidden):

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function trimStr(str){
return str.replace(/(^\s*)|(\s*$)/g,"");
}
function redisSearchSubmit(){
document.getElementById("searchtype").value = "Redis查询";
document.form1.submit();
} function jdbcSearchSubmit(){
document.getElementById("searchtype").value = "JDBC查询Mysql";
document.form1.submit();
} function hibernateSearchSubmit(){
document.getElementById("searchtype").value = "Hibernate查询Mysql";
document.form1.submit();
}
function check(){ // 节目名
var assetname = document.form1.assetname.value;
if(trimStr(assetname) == ""){
alert("您输入的节目名是空格,请重新输入");
return false;
} // 导演
var director = document.form1.director.value; // 编剧
var screenwriter = document.form1.screenwriter.value; //主演
var actor = document.form1.actor.value;
} </script>
</head>
<body>
<h1>查询页面</h1>
<FORM name="form1" METHOD=POST ACTION="${ pageContext.request.contextPath }/redisSqlSearch" onsubmit="return check();">
<input type="hidden" name="searchtype" id="searchtype" value="" />
<TABLE border="1" width="500">
<TR>
<TD>节目名称</TD>
<TD><INPUT TYPE="text" NAME="assetname" value=""></TD>
</TR>
<TR>
<TD>导演</TD>
<TD><INPUT TYPE="text" NAME="director" value="冯小刚"></TD>
</TR>
<TR>
<TD>编剧</TD>
<TD><INPUT TYPE="text" NAME="screenwriter" value="顾晓阳"></TD>
</TR>
<TR>
<TD>主演</TD>
<TD><INPUT TYPE="text" NAME="actor" value="葛优"></TD>
</TR>
<TR>
<TD colspan="2">
<INPUT TYPE="button" value="Redis查询" onclick="redisSearchSubmit()"> <INPUT TYPE="button" value="JDBC查询Mysql" onclick="jdbcSearchSubmit()"> <INPUT TYPE="button" value="Hibernate查询Mysql" onclick="hibernateSearchSubmit()">
</TD>
</TR>
</TABLE>
</FORM>
</body>
</html>

Form表单中不同的按钮进行不同的跳转的更多相关文章

  1. form表单中的button按钮

    如果在form表单中 , 存在button元素,button元素就充当了submit的角色

  2. 如何阻止form表单中的button按钮提交

    <form action="#" method="post"> <input type="text" name=" ...

  3. form表单中新增button按钮,点击按钮表单会进行提交

    原生button控件,在非ie浏览器下,如果不指定type,默认为submit类型.如果不想自动提交表单,指定type=“button”

  4. 在一个form表单中根据不同按钮实现多个action事件

    <form id="writeForm" method="post"> <div class="write-btn-tj" ...

  5. 关于form表单中button按钮自动提交问题

    坑:点击确认按钮,form表单提交2次,发送后台2次请求 //错误代码: <Button id="btnSubmit" name="btnSubmit" ...

  6. form表单中button按钮返回上一页解决办法

    解决Form中button按钮不好用的问题解决办法. 方法一: 1.在Form表单标签中国增加一个属性,如下图,红框处 2.返回按钮样式 3.onclick方法需要跳转的页面,遮挡处为需要返回的页面 ...

  7. form表单中多个button按钮必须声明type类型

    最近在做一个后台管理系统,发现了一个小bug: 问题描述:form表单中有多个button按钮(以下图为例),如果第一个button不写type属性,那么点击第一个button按钮会触发submit事 ...

  8. dwz的form表单中url的变量替换

    form表单中action的地址格式 “__URL__/edit/{xxx}”,大括号内的 “xxx” 就是变量名,主要功能是结合table组件一起使用. 下图中的删除.编辑.修改密码都是用了url变 ...

  9. form表单reset重置按钮

    如果ajax提交完数据,后想清空表单内容 ,以前都是用这个方法$("#id").val(""); 一个一个清空的,其实可以在form表单中加个隐藏的<in ...

随机推荐

  1. Mybatis-Plus 实战完整学习笔记(十一)------条件构造器删除,修改,conditon

    1.修改功能--其他过滤方式跟select一样 /** * 修改条件构造器 * @throws SQLException */ @Test public void selectUpdate() thr ...

  2. jquery取消事件冒泡的三种方法展示

    jquery取消事件冒泡的三种方法展示 html代码 <!doctype html> <html> <head> <meta charset="ut ...

  3. 【慕课网实战】Spark Streaming实时流处理项目实战笔记十二之铭文升级版

    铭文一级: ======Pull方式整合 Flume Agent的编写: flume_pull_streaming.conf simple-agent.sources = netcat-sources ...

  4. silverlight 定时器 System.Windows.Threading.DispatcherTimer

    声明 System.Windows.Threading.DispatcherTimer _MessageControler; //刷新 _MessageControler = new System.W ...

  5. 移动端 - Android客户端性能测试常见指标

    rom版本的性能测试 一般关注功耗(不过 rom 版本的功耗测试跟应用的功耗测试会有所差异,当然只是用例设计方面的差异,工具仍然采用安捷伦电源仪进行) 应用的性能测试 包括很多测试项,如启动时间.内存 ...

  6. Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)

    https://codeforces.com/contest/1118/problem/D1 能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1 首先对容量进行从大到小的排序, sor ...

  7. POJ3046--Ant Counting(动态规划)

    Bessie was poking around the ant hill one day watching the ants march to and fro while gathering foo ...

  8. TryEnterCriticalSection___Delphi

    VOID EnterCriticalSection:非阻塞函数.将当前线程对指定临界区的引用计数减1:在使用计数变为零时,另一等待此临界区的一个线程将被唤醒. BOOL TryEnterCritica ...

  9. [mysql] mysql 查询语句收集

    // 1. 筛选出当天的中奖名单            $where = " date_format(f_ctime,'%Y-%m-%d') = current_date()"; ...

  10. DELPHI获取宽带IP

    DELPHI获取宽带IP   DELPHI获取宽带IP procedure TForm1.Button1Click(Sender: TObject);varurl: string;beginurl : ...