gpt4 book ai didi

javascript - 表单不接受表单中的所有输入行(输入名称丢失(

转载 作者:行者123 更新时间:2023-12-03 08:24:33 24 4
gpt4 key购买 nike

我有这段代码,我需要获取在插入行和输入文本表单中输入的输入计数。请问有人可以帮助我吗?

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>";
}
?>

最佳答案

表单不允许是 table、tbody 或 tr 的子元素。

您可以在表单中包含整个表格。您可以在表格单元格内放置一个表单。表单中不能包含表格的一部分。

在整个表格中使用一种表格。然后使用单击的提交按钮来确定要处理哪一行(要快速)或处理每一行(允许批量更新)。

一切都很好。把你的<form> & </form > 外面的 table 。 <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>

有关更多信息,请查看 this

关于javascript - 表单不接受表单中的所有输入行(输入名称丢失(,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33613193/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com