JavaScript-Tableの現在の行を削除
8909 ワード
HTMLコード:
Jsコード:
転載先:https://www.cnblogs.com/dcy521/p/11390272.html
<body>
<table border="1" width="1000" height="200">
<tr>
<td> td>
<td> td>
<td> td>
<td> td>
tr>
<tr>
<td> td>
<td> td>
<td> td>
<td>
<a href="javascript:;" onclick='{if(confirm(" ?")) {deleteTr(this); }else {}}'> a>
td>
tr>
<tr>
<td> td>
<td> td>
<td> td>
<td>
<a href="javascript:;" onclick='{if(confirm(" ?")) {deleteTr(this); }else {}}'> a>
td>
tr>
<tr>
<td> td>
<td> td>
<td> td>
<td>
<a href="javascript:;" onclick='{if(confirm(" ?")) {deleteTr(this); }else {}}'> a>
td>
tr>
table>
body>
Jsコード:
<span style="color:#008000;">//</span><span style="color:#008000;">obj this</span>
<span style="color:#0000ff;">function</span><span style="color:#000000;"> deleteTr(obj) {
</span><span style="color:#008000;">//</span><span style="color:#008000;"> this </span>
<span style="color:#0000ff;">var</span> tr =<span style="color:#000000;"> obj.parentNode.parentNode;
</span><span style="color:#008000;">//</span><span style="color:#008000;"> </span>
<span style="color:#0000ff;">var</span> tbody =<span style="color:#000000;"> tr.parentNode;
</span><span style="color:#008000;">//</span><span style="color:#008000;"> </span>
<span style="color:#000000;"> tbody.removeChild(tr);
</span><span style="color:#008000;">//</span><span style="color:#008000;"> </span>
<span style="color:#0000ff;">if</span> (tbody.rows.length == 1<span style="color:#000000;">) {
tbody.parentNode.removeChild(tbody);
}
}
</span>
転載先:https://www.cnblogs.com/dcy521/p/11390272.html