在一個form表單中實現多個submit不同的action


在button中用JS的事件綁定onclick實現,如下:

<!-- employees是表單的name屬性值-->
 <script type="text/javascript">
     //一個表單實現多submit按鈕不同URL請求
     function toAdd() {
         document.employees.action = "add.do";
         document.employees.submit();
     }

     function toDelete(obj) {
         var n = obj.parentNode.parentNode.rowIndex;
         /*         document.getElementById('myTable').deleteRow(n); */
         document.employees.action = "delete.do";
         document.employees.submit();
     }
 </script>

<form method="post" name="employees">
     <!--table的id值 配合js可實現刪除表格的某一行  -->
         <table id="myTable">
             <tr>
                 <th colspan="5">員工信息管理</th>
             </tr>
             <tr>
                 <td>編號</td>
                 <td>姓名</td>
                 <td>年齡</td>
                 <td>薪資</td>
                 <td>操作</td>
             </tr>
             <tr>
                 <td><input class="input" type="text" name="employee_ID"></td>
                 <td><input class="input" type="text" name="employee_Name"></td>
                 <td><input class="input" type="text" name="employee_Age"></td>
                 <td><input class="input" type="text" name="employee_Salary"></td>
 
                 <td></td>
             </tr>
             <tr>
             <!--獲取員工信息,在表格中顯示出來,應用開始執行時要判斷非空,否則會拋空指針異常;
                 for循環遍歷在重定向后把ArrayList中的員工信息全部顯示出來。
               -->
                 <%
                     if (myEmp != null) {
                         for (Employee emp : myEmp) {
                 %>
                 <td><%=emp.getEmNum()%></td>
                 <td><%=emp.getEmName()%></td>
                 <td><%=emp.getEmAge()%></td>
                 <td><%=emp.getEmSalary()%></td>
                 <td><button name="delSelect" value="<%=++empCount%>"
                         onclick="toDelete(this)">刪除</button></td>            <!--實現員工存儲序號記錄以把值傳給servlet處理  -->
             </tr>
             <%
                 }
                 }
             %>
             <tr>
                 <td colspan="5">
        <input type="button" name="add" value="添加" onclick="toAdd()" />
         </td>
             </tr>
         </table>
 </form>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM