私は父と息子の関係を持つテーブルを持っています。父親を削除すると、その下の息子も削除されます。個々の息子を削除することもできます。これまでのコードは、対応する ID を持つ父または息子を削除せず、テーブルの最初のものを削除します。 これが私のコードです:
<script>
function delVesselAll(num){
$("#vessel_tab #father" + num).remove();
$("#vessel_tab .son" + num).remove();
document.getElementById(id).style.display = 'block';
};
function delSon(num){
$("#vessel_tab #son" + num).remove();
document.getElementById(id).style.display = 'block';
};
</script>
そして私のHTML:
<table id="vessel_tab">
<tr id="father1">
<td colspan="2" class="father_header">Father 1</td>
<td><a style="text-decoration:none;" onclick="showModal('delAllModal')"><input type="button" value="delete" onclick="showModal('delAllModal')"></a></td>
<div class="delModal" style="z-index:999999; margin-left:200px; margin-top:10px; display:none" id="delAllModal">
Are you sure you want to delete the father and corresponding sons?<br /><input type="button" value="Cancel" class="hide" onclick="hideModal('delAllModal')"/><input type="button" value="Delete" onclick="delVesselAll(1)" id="delete"/></div>
</tr>
<tr class="son1" id="son1">
<td> </td>
<td>Son 1</td>
<td><a style="text-decoration:none;" onclick="showModal('delSonModal')"><input type="button" value="delete"></a></td>
<div class="delModal" style="z-index:999999; margin-left:200px; margin-top:30px; display:none" id="delSonModal">
Please confirm deletion.<br /><input type="button" value="Cancel" class="hide" onclick="hideModal('delSonModal')"/><input type="button" value="Delete" onclick="delSon(1)"/></div>
</tr>
<tr class="son2" id="son2">
<td> </td>
<td>Son 2</td>
<td><a style="text-decoration:none;" onclick="showModal('delSonModal')"><input type="button" value="delete"></a></td>
<div class="delModal" style="z-index:999999; margin-left:200px; margin-top:30px; display:none" id="delSonModal">
Please confirm deletion.<br /><input type="button" value="Cancel" class="hide" onclick="hideModal('delSonModal')"/><input type="button" value="Delete" onclick="delSon(2)"/></div>
</tr>
<tr id="father2">
<td colspan="2">Father 2</td>
<td><a style="text-decoration:none;" onclick="showModal('delAllModal')"><input type="button" value="delete"></a></td>
<div class="delModal" style="z-index:999999; margin-left:200px; margin-top:10px; display:none" id="delAllModal">
Are you sure you want to delete the father and corresponding sons?<br /><input type="button" value="Cancel" class="hide" onclick="hideModal('delAllModal')"/><input type="button" value="Delete" onclick="delVesselAll(2)" id="delete"/></div>
</tr>
<tr class="son3" id="son3">
<td> </td>
<td>Son 3</td>
<td><a style="text-decoration:none;" onclick="showModal('delSonModal')"><input type="button" value="delete"></a></td>
<div class="delModal" style="z-index:999999; margin-left:200px; margin-top:30px; display:none" id="delSonModal">
Please confirm deletion.<br /><input type="button" value="Cancel" class="hide" onclick="hideModal('delSonModal')"/><input type="button" value="Delete" onclick="delSon(3)"/></div>
</tr>
<tr class="son4" id="son4">
<td> </td>
<td>Son 4</td>
<td><a style="text-decoration:none;" onclick="showModal('delSonModal')"><input type="button" value="delete"></a></td>
<div class="delModal" style="z-index:999999; margin-left:200px; margin-top:30px; display:none" id="delSonModal">
Please confirm deletion.<br /><input type="button" value="Cancel" class="hide" onclick="hideModal('delSonModal')"/><input type="button" value="Delete" onclick="delSon(4)"/></div>
</tr>
</table>
また、jsfiddle。正しく動作していません (何が間違っていたのかわかりません) が、私のコードはそこにあります。前もって感謝します! http://jsfiddle.net/7tFFS/1/