最佳答案
我想绑定到关闭 escape
上的主动反应引导弹出窗口。这里是代码
_handleEscKey: function(event) {
console.log(event);
if (event.keyCode == 27) {
this.state.activePopover.hide();
}
},
componentWillMount: function() {
BannerDataStore.addChangeListener(this._onchange);
document.addEventListener("click", this._handleDocumentClick, false);
document.addEventListener("keyPress", this._handleEscKey, false);
},
componentWillUnmount: function() {
BannerDataStore.removeChangeListener(this._onchange);
document.removeEventListener("click", this._handleDocumentClick, false);
document.removeEventListener("keyPress", this._handleEscKey, false);
},
但是当我按任何键时,控制台中没有记录任何东西。我也试着在窗口和不同的情况下“按键”,“关键字”等,但似乎我做错了什么。