In the development work, we often encounter a form that needs to contain multiple actions for different submission actions. At this time, we cannot use the submit button for submission, the following describes how to implement this function through Js.
1 2 3 4 5 6 7 8 |
< form name = "demo" method = "post" > <!--YOUR DATA AREA--> < input type = "button" value = "Add" onclick = "addAction()" > < input type = "button" value = "Delete" onclick = "deleteAction()" > < input type = "button" value = "Save" onclick = "saveAction()" > < input type = "button" value = "Query" onclick = "searchAction()" > </ form > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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> |
The name attribute must be added to the form to locate the access form through the document. Do not write the action attribute.