当我遇到<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中找到它。这是错字吗?
答案 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();
}
你很好走!!