gpt4 book ai didi

html - 如何在单个 HTML 表单中提交多个值?

转载 作者:行者123 更新时间:2023-12-04 17:31:35 25 4
gpt4 key购买 nike

所以我有一个 HTML 表单:

<html>
<body>
<script>history.pushState('', '', '/')</script>
<form action="http://myserver.com" method="POST">
<input type="hidden" name="Id" value="83" />
<input type="hidden" name="url" value="http://example.com/" />
<input type="submit" value="Submit request" />
</form>
<script>
document.forms[0].submit();
</script>
</body>
</html>

如您所见,这是提交 <input type="hidden" name="Id" value="83" /> 的操作这意味着它是针对与 ID 号 83 关联的属性提交的,我希望针对多个 ID 值(即 1 - 100)提交操作。这可能吗?如果是这样怎么办?

最佳答案

我假设你想做这样的事情

<html>
<body>
<script>history.pushState('', '', '/')</script>
<form action="http://myserver.com" method="POST">
<input type="hidden" name="Id[]" value="83" />
<input type="hidden" name="Id[]" value="85" />
<!-- you can add as many as input here for id if you want -->
<input type="hidden" name="url" value="http://example.com/" />
<input type="submit" value="Submit request" />
</form>
<script>
document.forms[0].submit();
</script>
</body>
</html>

发布此表单后,在服务器端,您可以将 $_POST['id'] 作为数组获取并使用它。

关于html - 如何在单个 HTML 表单中提交多个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43267778/

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