我有这段代码,我需要得到在插入行和输入文本表单时输入的输入数。有人能帮我吗?
function myFunction() {
var table = document.getElementById("mytable");
var rowCount = table.rows.length;
var row = table.insertRow(rowCount - 1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = table.rows[0].cells[0].innerHTML;
cell2.innerHTML = table.rows[0].cells[1].innerHTML;
}
<table id="mytable">
<form method="POST">
<tr>
<td>
<input name="s1[]" type="text" />
</td>
<td>
<input name="s2[]" type="text" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="insert" />
</td>
</tr>
</form>
</table>
<button onclick="myFunction()">more</button>
<?php if(isset($_POST[ 'submit']))
{
$count = count($_POST[ 's1']);
echo "<script>alert('".$count. "');</script>";
}
?>
表单不允许是表、tbody或tr.的子元素
你可以在一个窗体中有一整张表。你可以在表单元格中有一个窗体。表单中不能包含表的一部分。
在整张桌子周围使用一个表格。然后,使用单击的提交按钮来确定要处理哪一行(为了快速)或处理每一行(允许批量更新)。
一切都很好。把你的<form>
&</form
>表外。<table></table>
应在<form></form>
内
<form method="POST">
<table id="mytable">
<tr>
<td>
<input name="s1[]" type="text" />
</td>
<td>
<input name="s2[]" type="text" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="insert" />
</td>
</tr>
</table>
</form>
有关更多信息,请查看此
也许你应该把表放在表单中:
<form method="POST">
<table id="mytable">
<tr>
<td>
<input name="s1[]" type="text" />
</td>
<td>
<input name="s2[]" type="text" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="insert" />
</td>
</tr>
</table>
</form>