假设我们有:
<form action="xxx">
<input type="checkbox" id = "checkbox" name="checked" value="1">
<input type="submit">Submit</input>
</form>"
当点击提交按钮时,url 应该类似于“xxx?checked=1”。在这种情况下,我想将另一个参数附加到 url。我知道使用隐藏值是一种选择,但我们有更直接的方法吗?请建议。谢谢
最佳答案
事实上,url 取决于您用来发送表单的方法。这是在 the method
attribute 上设置的在 the <form>
tag .
action
的 URL可以是任何有效的 URL,以便添加额外的属性,如 something=1
和 other=2
您可以设置以下内容:
<form action="xxx?something=1&other=2">
<input type="checkbox" id="checkbox" name="checked" value="1">
<input type="submit">Submit</input>
</form>
提交表单现在将发送 GET
请求xxx?something=1&other=2&checked=1
关于html - 如何更改发送到 html 表单的 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16994875/