删除当前行的JS代码!请大家帮我看看。急!!!!
我要通过按钮删除当前行,该怎么样执行!代码如下!请大家帮我看看。急!!!!
var currRowIndex = 0;
function del(objTD)
{
var objTR =objTD.parentElement
currRowIndex= objTR.rowIndex;
alert(currRowIndex);
var objTable = document.getElementById( "t ");
if(confirm( "确定删除? "))
{
objTable.deleteRow(currRowIndex);
currRowIndex = 0;
}
}
<table>
<tr id=a1>
<td> 1111 </td>
<td>
<button type= "button " name= "b1 " onClick= "javascript:del(this) "> del </button>
</td>
</tr>
<tr id=a2>
<td> 222222222 </td>
<td>
<button type= "button " name= "b2 onClick= "javascript:del(this) "> del </button>
</td>
</tr>
<tr id=a3>
<td> 3333333333 </td>
<td>
<button type= "button " name= "b3 " onClick= "javascript:del(this) "> del </button>
</td>
</tr>
</table>
------解决方案-------------------- <script>
var currRowIndex = 0;
function del(objTD)
{
var objTR =objTD.parentElement.parentElement;
currRowIndex= objTR.rowIndex;
alert(currRowIndex);
var objTable = document.getElementById( "t ");
if(confirm( "确定删除? "))
{
objTable.deleteRow(currRowIndex);
currRowIndex = 0;
}
}
</script>
<table id= "t ">
<tr id=a1>
<td> 1111 </td>
<td>
<button type= "button " name= "b1 " onClick= "del(this) "> del </button>
</td>
</tr>
<tr id=a2>
<td> 222222222 </td>
<td>
<button type= "button " name= "b2 " onClick= "del(this) "> del </button>
</td>
</tr>
<tr id=a3>
<td> 3333333333 </td>
<td>
<button type= "button " name= "b3 " onClick= "del(this) "> del </button>
</td>
</tr>
</table>
------解决方案-------------------- <script>
var currRowIndex = 0;
function del(objTD)
{
var objTR =objTD.parentNode.parentNode;
currRowIndex= objTR.rowIndex;
if(confirm( "确定删除? "))
{
objTR.parentNode.deleteRow(currRowIndex);
currRowIndex = 0;
}
}
</script>
<table id= "t ">
<tr id=a1>
<td> 1111 </td>
<td>
<button type= "button " name= "b1 " onClick= "del(this) "> del </button>
</td>
</tr>
<tr id=a2>
<td> 222222222 </td>
<td>
<button type= "button "