HTMLFormElement 方法 requestSubmit() requests that the form be submitted using a specific submit button.

句法

htmlFormElement.requestSubmit(submitter);
					

参数

submitter 可选

The submit button whose attributes describe the method by which the form is to be submitted. This may be either an <input> or <button> element whose type 属性为 submit .

If you omit the submitter parameter, the form element itself is used as the submitter.

返回值

None.

异常

TypeError
指定 submitter is not a submit button.
NotFoundError
指定 submitter isn't a member of the form on which requestSubmit() was called. The submitter must be either a descendant of the form element or must have an form attribute referring to the form.

用法注意事项

The obvious question is: Why does this method exist, when we've had the submit() method since the dawn of time?

The answer is simple. submit() submits the form, but that's all it does. requestSubmit() , on the other hand, acts as if a submit button were clicked. The form's content is validated, and the form is submitted only if validation succeeds. Once the form has been submitted, the submit event is sent back to the form object.

范例

In the example below, the form is submitted by attempting to send the request using requestSubmit() if it's available. If a submit button with the ID main-submit is found, that's used to submit the form. Otherwise, the form is submitted with no submitter parameter, so it's submitted directly by the form itself.

If, on the other hand, requestSubmit() isn't available, this code falls back to calling the form's submit() 方法。

let myForm = document.querySelector("form");
let submitButton = myForm.querySelector("#main-submit");
if (myForm.requestSubmit) {
  if (submitButton) {
    myForm.requestSubmit(submitButton);
  } else {
    myForm.requestSubmit();
  }
} else {
  myForm.submit();
}
					

规范

规范 状态 注释
HTML 实时标准
The definition of 'requestSubmit()' in that specification.
实时标准

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
requestSubmit() Chrome 76 Edge 79 Firefox 75 IE No Opera 63 Safari No WebView Android 76 Chrome Android 76 Firefox Android No Opera Android 54 Safari iOS No Samsung Internet Android 12.0

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改:
  1. HTMLFormElement
  2. 特性
    1. acceptCharset
    2. action
    3. 元素
    4. encoding
    5. enctype
    6. length
    7. method
    8. 名称
    9. target
  3. 方法
    1. reportValidity()
    2. requestSubmit()
    3. reset()
    4. submit()
  4. 事件
    1. formdata
    2. reset
    3. submit
  5. 继承:
    1. HTMLElement
    2. 元素
    3. 节点
    4. EventTarget
  6. HTML DOM 相关页面
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. GlobalEventHandlers
    5. HTMLAnchorElement
    6. HTMLAreaElement
    7. HTMLAudioElement
    8. HTMLBRElement
    9. HTMLBaseElement
    10. HTMLBaseFontElement
    11. HTMLBodyElement
    12. HTMLButtonElement
    13. HTMLCanvasElement
    14. HTMLContentElement
    15. HTMLDListElement
    16. HTMLDataElement
    17. HTMLDataListElement
    18. HTMLDialogElement
    19. HTMLDivElement
    20. HTMLDocument
    21. HTMLElement
    22. HTMLEmbedElement
    23. HTMLFieldSetElement
    24. HTMLFormControlsCollection
    25. HTMLFrameSetElement
    26. HTMLHRElement
    27. HTMLHeadElement
    28. HTMLHeadingElement
    29. HTMLHtmlElement
    30. HTMLIFrameElement
    31. HTMLImageElement
    32. HTMLInputElement
    33. HTMLIsIndexElement
    34. HTMLKeygenElement
    35. HTMLLIElement
    36. HTMLLabelElement
    37. HTMLLegendElement
    38. HTMLLinkElement
    39. HTMLMapElement
    40. HTMLMediaElement
    41. HTMLMetaElement
    42. HTMLMeterElement
    43. HTMLModElement
    44. HTMLOListElement
    45. HTMLObjectElement
    46. HTMLOptGroupElement
    47. HTMLOptionElement
    48. HTMLOptionsCollection
    49. HTMLOutputElement
    50. HTMLParagraphElement
    51. HTMLParamElement
    52. HTMLPictureElement
    53. HTMLPreElement
    54. HTMLProgressElement
    55. HTMLQuoteElement
    56. HTMLScriptElement
    57. HTMLSelectElement
    58. HTMLShadowElement
    59. HTMLSourceElement
    60. HTMLSpanElement
    61. HTMLStyleElement
    62. HTMLTableCaptionElement
    63. HTMLTableCellElement
    64. HTMLTableColElement
    65. HTMLTableDataCellElement
    66. HTMLTableElement
    67. HTMLTableHeaderCellElement
    68. HTMLTableRowElement
    69. HTMLTableSectionElement
    70. HTMLTemplateElement
    71. HTMLTextAreaElement
    72. HTMLTimeElement
    73. HTMLTitleElement
    74. HTMLTrackElement
    75. HTMLUListElement
    76. HTMLUnknownElement
    77. HTMLVideoElement
    78. HashChangeEvent
    79. 历史
    80. ImageData
    81. 定位
    82. MessageChannel
    83. MessageEvent
    84. MessagePort
    85. Navigator
    86. NavigatorGeolocation
    87. NavigatorID
    88. NavigatorLanguage
    89. NavigatorOnLine
    90. NavigatorPlugins
    91. PageTransitionEvent
    92. Plugin
    93. PluginArray
    94. PopStateEvent
    95. PortCollection
    96. PromiseRejectionEvent
    97. RadioNodeList
    98. Transferable
    99. ValidityState
    100. Window
    101. WindowBase64
    102. WindowEventHandlers
    103. WindowTimers