日期:2014-05-17 浏览次数:20720 次
function addRow()
{
var tb = $("tb");
if (tb == null) return ;
var rows = tb.rows.length;
var rowID = rows;
document.getElementById("rows").value = rows;
var tr1 = tb.insertRow(rows);
var td1 = tr1.insertCell();
td1.innerHTML = ""+ rowID +".<input size=12 name=\"A" + rowID + "\"/ ><font color=#ff0000> *</font> "
var td2 = tr1.insertCell();
td2.innerHTML = "<input size=6 name=\"B" + rowID + "\" /> <font color=#ff0000> *</font>"
var td3 = tr1.insertCell();
td3.innerHTML = "<input size=8 name=\"C" + rowID + "\" /><font color=#ff0000> *</font>"
var td4 = tr1.insertCell();
td4.innerHTML = "<input size=50 name=\"beizhu" + rowID + "\" />"
}
function removeRowFromTable()
{
var tb = document.getElementById('tb');
var lastRow = tb.rows.length;
if (lastRow > 2) tb.deleteRow(lastRow - 1);
}
<table id="tb" border="0" width="556">
<tr><td车号</td><td>
件数</td><td>重量</td><td>备注</td></tr>
<tr><td>1.<input name="A1" size="12">
</td><td><input name="B1" size="6"></td><td>
<input name="C1" size="8"></td><td><input name="beizhu1" size="50" ></td></tr>
</table><input type="button" onclick="addRow()" value="增加一个"/ ><input type="button" value="删除一个" onclick="removeRowFromTable();" /><div id="table1"><input type="hidden" id="rows" name="rows" value="1"/>