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

ElementInternals: setFormValue() method

· 52CE 我爱测

The **`setFormValue()`** method of the ElementInternals interface sets the element's submission value and state, communicating these to the user agent.

Web Components

The setFormValue() method of the ElementInternals interface sets the element's submission value and state, communicating these to the user agent.

Syntax

setFormValue(value)
setFormValue(value, state)

Parameters

  • value
    • : A File, a string, or a FormData as the value to be submitted to the server.
  • state
    • : A File, a string, or a FormData representing the input made by the user. This allows the application to re-display the information that the user submitted, in the form that they submitted it, if required.

[!NOTE] In general, state is used to pass information specified by a user, the value is suitable for submission to a server, post sanitization. For example, if a custom element asked a user to submit a date, the user might enter "3/15/2019". This would be the state. The server expects a date format of 2019-03-15, the date in this format would be passed as the value.

Return value

Undefined.

Exceptions

  • NotSupportedError DOMException
    • : Thrown if the element does not have its formAssociated property set to true.

Examples

In the following example, a checkbox custom element sets on as the value to send to the server, and checked as the state.

this.internals_.setFormValue("on", "checked");

Specifications

Browser compatibility

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

资料来源与适用范围

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

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

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