提问者:小点点

如何从另一页获取表单操作信息[重复]


<form action = "AnotherPage.php" method = "get">
    <table id="uniqueID">
        <tr>
            <td><input id="box1" type="checkbox" name="box1" value = "apple"/><label
                    for="box1">apples</label></td>
        </tr>

    </table>
    <input type="submit" value="Submit">

</form>

那么,当用户提交它时,我如何获取anotherpage.html中的box1=apple信息。 谢谢,最好不要jQuery。 所以我希望一个otherpage.html文件做console.log(方框1=apple)和一个otherpage的html文件。 “方框1=苹果”(当然没有对它们进行硬编码)

编辑。 所以我认为用PHP做比较好。 如何在anotherpage.php中回显这些数据


共1个答案

匿名用户

如果要使用纯HTML和 没有任何后端服务器的JS,您可以将带有get方法的表单数据作为URI查询参数发送到下一页:

<form action = "anotherPage.html" method = "get">
    <table id="uniqueID">
        <tr>
            <td><input id="box1" type="checkbox" name="box1" value = "apple"/><label
                    for="box1">apples</label></td>
        </tr>

    </table>
    <input type="submit" value="Submit">
</form>

并从下一页的URI查询中解析它:

<html>
  <body>
  <script>
    const urlParams = new URLSearchParams(window.location.search);
    const apples = urlParams.get('box1');
    console.log(apples);
  </script>
  </body>
</html>