我正在使用 ReactJs 来开发我的应用程序。我试图通过处理 onKeyPress 事件在按下 Enter 时提交输入文本。它检测其他输入,但不输入。我尝试过不同的方法——event.key
, event.charCode
, event.keyCode
, event.which
……似乎没什么作用。
React.createElement("input", {tabIndex: "1", onKeyPress: this.handleKeyPress, onChange: this.handleChange,
placeholder: "ex: 1,10,15"}),
handleChange: function (event) {
this.setState({userInputBuckets: event.target.value});
},
handleKeyPress: function (event) {
if (event.charCode == 13) {
event.preventDefault();
this.props.table.handleSubtotalBy(this.props.columnDef, this.state.userInputBuckets);
}
},
我也尝试过onKewDown
处理时,它会检测到正确的键,但即使它评估,它也不会执行 if 块event.keyCode == 13
是真的。
Move e.stopPropagataion
from handleSubtotalBy
into handleKeyPress
:
handleKeyPress(event) {
if (event.charCode == 13) {
event.preventDefault();
event.stopPropagation();
this.props.table.handleSubtotalBy(this.props.columnDef, this.state.userInputBuckets);
}
}
handleSubtotalBy(columnDef, partitions) {
const subtotalBy = this.state.subtotalBy || [];
// ...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)