【问题标题】:how to get form action information from another page [duplicate]如何从另一个页面获取表单操作信息[重复]
【发布时间】:2020-06-17 14:06:10
【问题描述】:
<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。所以我希望anotherPage.html 文件执行console.log(box 1 = apple) 并在anotherPage 的html 文件中。 “box 1 = apple”(当然没有硬编码)

编辑。所以我认为最好用php来做。我将如何在 AnotherPage.php 中回显这些数据

【问题讨论】:

  • 能否将信息添加到 json 文件中,然后从另一个页面中的 json 中提取该信息?
  • 当以 HTML 格式提交表单时,它会通过 GET 或 POST 将数据(输入)发送到其他页面。您应该阅读有关 HTTP 请求的更多信息。
  • 用 html javascript 是不可能的。我需要使用php吗?
  • 可以使用localStorage或cookie信息保存formaction详情
  • 您可以使用 if iseet box1 和 php 并回显该值...

标签: javascript php html


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-28
    • 2012-11-02
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多