【发布时间】:2017-04-03 05:52:44
【问题描述】:
当我按下“Enter”按钮时,我正在尝试加载我制作的新组件。我已经成功实现了onKeyPress函数,如下。
class SearchBar extends Component {
constructor(props) {
super(props);
this.handleKeyPress = this.handleKeyPress.bind(this);
}
handleKeyPress(e) {
if (e.key === 'Enter') {
console.log("load new page");
}
}
render() {
return (
<div className="search_bar_div">
<div className="search_bar_internal_div">
{/* Search bar for desktop and tablets */}
<span className="Rev_logo">Revegator</span>
<input type="search" placeholder="Search here" className="search_bar"
onKeyPress={this.handleKeyPress}/>
</div>
</div>
}
我正确获取了控制台日志,但我遇到的问题是当我按 Enter 时如何加载组件。
【问题讨论】:
标签: javascript reactjs