首页 > 代码库 > 一个Form多个提交动作Submit的解决方法

一个Form多个提交动作Submit的解决方法

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

1
2
3
4
5
6
7
8
     
< 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 >
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<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>

form表单一定要添加上name属性,以通过document定位访问表单,不要写action属性了