反应形式自动完成名字或电子邮件

react form autocomplete first name or email

我在反应中形成一般没什么特别的。

    <form onSubmit={click}>
    <input
      value={firstName}
      onChange={event => inputChangedHandler(event)}
    />
       <input
      value={email}
      onChange={event => inputChangedHandler(event)}
    />
  <Button >
    send
  </Button>
</form>

重点是 chrome 有时会为我自动完成 google 的信息,例如地址和邮政编码等。 有时不是。

我有一些组件是相同的输入字段,其中一个是,另一个不是。

有人可以向我解释一下它是如何工作的吗?

您正在创建一个表单,因此您不需要 <Button>,而是指定它是一个将要提交的表单。 <input type="submit" value="send" /> 这将创建一个按钮。

In order to provide autocompletion, user-agents might require <input>/<select>/<textarea> elements to:

  • Have a name and/or id attribute
  • Be descendants of a <form> element
  • The form to have a submit button

MDN 自动完成文档: The HTML autocomplete attribute

此外,the reactjs docs show you examples that will help, like this reactjs form codepen

如果你坚持预期的属性,你会有更好的运气。