<script>
//删除当前td标签
function del_accessory(tablename){
for(var i=2;i<3;i++){
//得到table第二行(第二个tr)的内容
var tab = document.getElementById(tablename).rows[(i)].cells[0].innerHTML;
if(tab != "" && i != 3){
//得到td
var td = document.getElementById(tablename).rows[(i)].cells[0]
//将当前td删除
td.removeNode(td);
//得到td的第0个元素
//var fob0 = td.childNodes[0];
//得到td的第1个元素
//var fob1 = td.childNodes[1];
//删除第0个元素
//fob0.parentNode.removeChild(fob0);
//删除第1个元素
//fob1.parentNode.removeChild(fob1)'
}
}
}
</script>
<table id = "table1">
<tr><td>删除td</td></tr>
<tr><td><input type="text"><input type="text"><input type="button" onclick=" del_accessory('table1')" value="取消">
</table>
<table id = "table2">
<tr><td>删除td</td></tr>
<tr><td><input type="text"><input type="text"><input type="button" onclick="del_accessory('table2')" value="取消">
</table>
-----------------------------------------------------------------------------------------------------------------
循环table里的元素
<script>
function del_accessory(tablename,ind){
var tb = document.getElementById(tablename);
var rows = tb.rows;
for(var i=0;j<rows.lenght;i+){
var cells = rows[i].cells;
for(var j = 0;j<cells.length;j++){
alert(cells[[j].innerHTML);
if(cells[j].name="god"){
if(cells[j].childNodes[6].value == ind){
alert(ind);
var td = document.getElementById(tablename).rows[(i)].cells[0];
td.removeNode(td);
}
}
}
}
}
</script>
<table id="table1">
<c:forench item="list" var="f" varStatus="i">
<tr>
<td name="god">
<input type="text" value="${f.name}"><input type="text" value="${f.value}">
<input type="button" value="取消" onclick="del_accessory('table1',${i.index})">
<input type="hidden" value="${i.index}"><td></tr>
</c:forench>
</table>