我正好有以下表格:
<form method="post" action=<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?> enctype="multipart/form-data">
<button type="submit" name="identifier" value="wikipedea_form">
Add Post
</button>
</form>我使用jquery将此表单提交为
$("form").submit();这不会发送post数据$_POST["identifier"]。我假设jQuery在引擎盖下使用HTMLFormElement.submit()。MDN文档说:
属性为“submit”的
<input>在使用HTMLFormElement.submit()时不会与表单一起提交.
我认为这同样适用于button标记。我想100%肯定我是在问你。可能取决于浏览器等等.
那么,在使用<button>时,属性为type="submit"的HTMLFormElement.submit()会不会与表单一起提交呢?请引用官方文件来支持你的回答。
发布于 2021-12-30 18:07:39
只有成功的控件才以正常形式提交。
只有当提交按钮用于提交表单时才会成功(或者如果表单是通过输入单个文本输入提交的,在这种情况下,默认的Submit按钮是成功的)。这样,您就可以区分在以下情况下使用哪个按钮提交表单:
<button name="action" value="like">Like</button>
<button name="action" value="dislike">Dislike</button>使用JS触发表单提交绕过了提交按钮的选择。
1. If any of the following is true:
- The field element has a datalist element ancestor.
- The field element is disabled.
- **The field element is a button but it is not submitter.**
- The field element is an input element whose type attribute is in the Checkbox state and whose checkedness is false.
- The field element is an input element whose type attribute is in the Radio Button state and whose checkedness is false.然后继续.
如果您希望每次提交表单时都提交带有表单的数据,无论它是如何提交的:请使用<input type="hidden" ...>
https://stackoverflow.com/questions/70534259
复制相似问题