Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
431 views
in Technique[技术] by (71.8m points)

React的input框只能用onChange来改变value值么?用onKeyUp为什么获取不到值

我在input标签里用了value={this.state.text} 然后组件初始化的时候设置了text:''
并且在input标签里绑定了事件onkeyUp={this.handleKeyUp}
最后在handleKeyUp(event)方法里用setState(text:event.target.value)
来获取输入的值并且改变text 然后重新渲染出来,,
在网上查了很多资料了 基本都是这种方式 只不过用的是onChange 但是我这里用onChange就不能监听键盘事件了 比如我想在input框里监听回车事件 用onChange就获取不到event对象 或者说有其他什么好的办法么?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

https://facebook.github.io/re...

boolean altKey
number charCode
boolean ctrlKey
boolean getModifierState(key)
string key
number keyCode
string locale
number location
boolean metaKey
boolean repeat
boolean shiftKey
number which

试试 charCode


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...