这是我的代码..我的问题是当我创建多行时,只有第一行才进入数据库..下一行不是..供您参考,添加行功能效果很好......我使用这个概念MVC 的
看法
<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 1) {
alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
</SCRIPT>
<fieldset>
<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
<TABLE id="dataTable" width="350px" border="1">
<TR>
<TD><INPUT type="checkbox" name="chk[]"/></TD>
<TD><INPUT type="text" name="amount[]"/></TD>
<TD><INPUT type="text" name="date[]" id="date" /></TD>
<td align="center" valign="top" nowrap><input name="count1" type="text" id="count1" size="8" maxlength="10" value="10"></td>
</TR>
</TABLE>
控制器
$count= $_POST['count1'];
$amount= $_POST['amount'];
$date= $_POST['date'];
for($i=0; $i<=10; $i++){
$this->Model->insertBil($date[$i],$amount[$i]);
}
型号 没有问题