大网数据广告活动
Web 标准与前端开发

SubmitEvent

· 52CE 我爱测

The **`SubmitEvent`** interface defines the object used to represent an HTML form's HTMLFormElement.submit_event event. This event is fired at the form when the form's submit action is invoked.

HTML DOM

The SubmitEvent interface defines the object used to represent an HTML form's HTMLFormElement.submit_event event. This event is fired at the form when the form's submit action is invoked.

Constructor

  • SubmitEvent.SubmitEvent
    • : Creates and returns a new SubmitEvent object whose Event.type and other options are configured as specified. Note that currently the only valid type for a SubmitEvent is submit.

Instance properties

In addition to the properties listed below, this interface inherits the properties of its parent interface, Event.

  • SubmitEvent.submitter
    • : An HTMLElement object which identifies the button or other element which was invoked to trigger the form being submitted.

Instance methods

While SubmitEvent offers no methods of its own, it inherits any specified by its parent interface, Event.

Examples

In this example, a shopping cart may have an assortment of different submit buttons depending on factors such as the user's settings, the shop's settings, and any minimum or maximum shopping card totals established by the payment processors. Each of the submit elements' Element.id is used to identify which payment processor the button corresponds to.

let form = document.querySelector("form");
form.addEventListener("submit", (event) => {
  let submitter = event.submitter;
  let handler = submitter.id;

  if (handler) {
    processOrder(form, handler);
  } else {
    showAlertMessage(
      "An unknown or unaccepted payment type was selected. Please try again.",
      "OK",
    );
  }
});

The handler ID is obtained by using the submit event's SubmitEvent.submitter property to get the submit button, from which we then get the ID. With that in hand, we can call a processOrder() function to handle the order, passing along the form and the handler ID.

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。