本文介绍了ReactJS处理文本区域中的制表符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在ReactJS中处理按Tab键的事件,以便能够缩进文本区域内的文本?
How can I handle tab key pressed events in ReactJS so I'm able to indent text inside a textarea?
在文本区域上按下Tab键时,不会触发onChange事件,因此我想可能可以使用更高级别的处理程序来检测此事件.
onChange event does not get fired when tab is pressed on the textarea, so I guess there might be a higher level handler I can use to detect this event.
推荐答案
您可以尝试onKeyDown并获取tab的密钥代码.
you can try onKeyDown and get the keycode for tab.
add: function(event){
console.log(event.keyCode); //press TAB and get the keyCode
},
render: function(){
return(
<div>
<input type="text" id="one" onKeyDown={this.add} />
</div>
);
}
这篇关于ReactJS处理文本区域中的制表符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!