id 和 name 是否必须在表单输入标签内匹配?

Do the id and name have to match inside form input tags?

我了解到 in XHTML 1.0 the name and id have to match,因为首先将其命名为 HTML 的属性,他们决定使用 id。

In XML, URI-references [RFC2396] that end with fragment identifiers of the form "#foo" do not refer to elements with an attribute name="foo"; rather, they refer to elements with an attribute defined to be of type ID, e.g., the id attribute in HTML 4. Many existing HTML clients don't support the use of ID-type attributes in this way, so identical values may be supplied for both of these attributes to ensure maximum forward and backward compatibility (e.g., ...).

那么今天什么被认为是合法的?

<br /> <!-- //--> <input />这样的标签仍然可以接受吗?

不,id 属性只是一种唯一标识 html 元素的方法。根据您创建 html 的方式(原始 html 与 css、react 等),此 id 可以多种方式使用。

name 属性通常用于标识 http 请求的 multipart-form-data 中的数据。

您也可以看这里:

  • difference between id and name attributes in html
  • name vs id attribute in html