表单标签是否具有属性类型?

时间:2019-06-11 05:22:26

标签: html

当我遇到<form type='submit'>时,我正在阅读一篇有关React在vanillaJS(here)上优势的博客文章。完整摘录是

render() {
return (
  <div>
    <h1>Search Hacker News with React</h1>
    <form type="submit" onSubmit={this.onSubmit}>
      <input type="text" onChange={this.onChange} />
      <button type="text">Search</button>
    </form>

    {/* show the list of items */}
  </div>
);
}

type的任何地方或MDN上都找不到<form>。我也无法在react docs中找到它。这是错字吗?

1 个答案:

答案 0 :(得分:0)

它的正确代码只是您必须删除类型

render() {
return (
  <div>
    <h1>Search Hacker News with React</h1>
    <form onSubmit={this.onSubmit}>
      <input type="text" onChange={this.onChange} />
      <button type="text">Search</button>
    </form>

    {/* show the list of items */}
  </div>
);
}

并编写onSubmit应该执行的操作,类似于遵循

onSubmit(event) {
    alert('A name was submitted: ');
    event.preventDefault();
  }

你很好走!!