如何在textarea上捕获enter keypress而不是shift + enter? [英] How to catch enter keypress on textarea but not shift+enter?
本文介绍了如何在textarea上捕获enter keypress而不是shift + enter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为texarea做这件事。当用户按 Enter 时应该调用一个函数,但是当按下 Shift + Enter 时,不应该执行任何操作。
I'm doing it for texarea. A function should be called when the user press Enter, but nothing should be done when Shift + Enter be pressed.
我尝试在这里模拟许多IM通信器具有的功能:在 Enter 上发送消息,但也使用 Shift + <添加多行kbd>输入。
I try to simulate here a feature that many IM communicators have: sending a message on Enter but also adding multiple lines using Shift + Enter.
推荐答案
测试输入键码(13)并按下shift键。
Test for the enter keycode (13) and if shift key was pressed.
...onkeyup = function(e) {
if (e.keyCode == 13)
{
// if (e.shiftKey === true)
if (e.shiftKey) // thruthy
{
// new line
}
else
{
// run your function
}
return false;
}
}
编辑:全部接受truthy值 e.shiftKey
Accept all truthy values of e.shiftKey
这篇关于如何在textarea上捕获enter keypress而不是shift + enter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文