表单没有'我不接受表单中的所有输入行(缺少输入名称)

Form doesn't accept all inputs rows in my form (input names missing(

本文关键字:输入 表单 不接受      更新时间:2023-09-26

我有这段代码,我需要得到在插入行和输入文本表单时输入的输入数。有人能帮我吗?

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>