求助:删除table最后一行表单提交错误
本帖最后由 xiaolu2007 于 2013-12-12 17:01:15 编辑 我用以下代码定义动态增加行和删除最后一行,但是当只删除最后一行后提交表单就会出现删除行的空值问题,若是删除行后再增加行是正常的,求助解决,删除行后提交空值的问题呢?谢谢
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"/>