我有一個簡單的 Web 表單,其中還包含一個表格,允許用戶在提交表單之前洗掉表格行。我需要從提交表單時存在的表行中捕獲資料,但由于表中沒有表單輸入欄位,因此我的請求變數中沒有顯示這些欄位。
該表非常簡單,如下所示:
<table class="table table-condensed table-striped table-bordered">
<thead>
<th class="text-center" scope="col">Code</th>
<th class="text-center" scope="col">Name</th>
<th class="text-center" scope="col">Part ID</th>
</thead>
<tbody>
<tr>
<td>ABC123</td>
<td>Widgets - Small</td>
<td>S2000</td>
</tr>
<tr>
<td>ZXR987</td>
<td>Bolts - Large</td>
<td>G5600</td>
</tr>
</tbody>
</table>
我需要為提交表單時留下的每個表格行捕獲 Part ID 的值,但不確定這是否可行或如何去做?
uj5u.com熱心網友回復:
最簡單的方法是添加一個帶有 Part ID 的隱藏欄位。在下面的示例中,$_POST['partId']
將回傳一個剩余零件 ID 的陣列。
<table class="table table-condensed table-striped table-bordered">
<thead>
<th class="text-center" scope="col">Code</th>
<th class="text-center" scope="col">Name</th>
<th class="text-center" scope="col">Part ID</th>
</thead>
<tbody>
<tr>
<td>ABC123</td>
<td>Widgets - Small</td>
<td>S2000 <input type="hidden" name="partId[]" value="S2000"></td>
</tr>
<tr>
<td>ZXR987</td>
<td>Bolts - Large</td>
<td>G5600 <input type="hidden" name="partId[]" value="G5600"></td>
</tr>
</tbody>
</table>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/504263.html
標籤:javascript php html
下一篇:如何按特定鍵對物件陣列進行分組