POST 表单:如何将 GET 参数放入操作属性中?

Jac*_*chi 1 html forms post get

我有这个表格:

<!DOCTYPE html>
<html>
    <body>
        <form action="draft.html?test=1">
            <button type="submit">Valid</button>
        </form>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

但是当我单击 valid 时,它不会重定向到 Draft.html?test=1 而是重定向到 Draft.html。我究竟做错了什么?

感谢您的帮助。

编辑:我知道我应该赞成<input type="hidden">,但我想将它用于 POST 表单。

编辑2:这是一个愚蠢的问题,只要我将表单的方法更改为POST,问题就解决了。

Edg*_*ant 6

如果您绝对需要将其放在操作属性上,则可以使用method="POST".

<!DOCTYPE html>
<html>
    <body>
        <form action="draft.html?test=1" method="POST">
            <button type="submit">Valid</button>
        </form>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

GET否则,如果您想通过使用发送数据

<!DOCTYPE html>
<html>
    <body>
        <form action="draft.html" method="GET">
            <input type="hidden" name="test" value="1">
            <button type="submit">Valid</button>
        </form>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

9740 次

最近记录:

7 年,10 月 前