jsテーブル操作

950 ワード

<html>
<table id="t" border="1">
<tr><td>1</td></tr>
</table>
<input type="button" value="addRow" onclick="fun(t)">
<input type="button" value="delRow" onclick="del(t)">
</html>
<script type="text/javascript">
var rid=1;
function fun(t){
var newRow = t.insertRow();//    
newRow.id="r"+rid++;
var newCell=newRow.insertCell();//           
newCell.innerHTML="<a href='javascript:void(0)' onclick='addCell("+newRow.id+")'>addCell</a>"; //      
}
function del(t){
 t.deleteRow(t.rows.length-1);//      
 
}
function addCell(row){
var newCell = row.insertCell();
newCell.innerHTML=row.cells.length-1;

}
</script>