admin管理员组文章数量:1426617
I know that the shift key
code is 16
, and the enter key
code is 13
.
//@ catching any 'enter' keypress in textarea.
function textareaOnEnter(){
$('textarea#someId').keypress(function(e)
{
if(e.which == 13)
{
//.. works only for 'enter'
}
});
}
I thought it could be as simple as this:
function textareaOnShiftAndEnter(){
$('textarea#someId').keypress(function(e)
{
if(e.which == 13 && e.which == 16)
{
//.. don't work for nothing
}
});
}
But of course it simply doesn't work as I would expected. How do I check for shift + enter
key press?
I know that the shift key
code is 16
, and the enter key
code is 13
.
//@ catching any 'enter' keypress in textarea.
function textareaOnEnter(){
$('textarea#someId').keypress(function(e)
{
if(e.which == 13)
{
//.. works only for 'enter'
}
});
}
I thought it could be as simple as this:
function textareaOnShiftAndEnter(){
$('textarea#someId').keypress(function(e)
{
if(e.which == 13 && e.which == 16)
{
//.. don't work for nothing
}
});
}
But of course it simply doesn't work as I would expected. How do I check for shift + enter
key press?
- developer.mozilla/en-US/docs/Web/API/KeyboardEvent/shiftKey – Dr.Molle Commented Sep 16, 2015 at 2:08
-
1
e.which
could never be both 13 and 16 at the same time :P. You want modifier keys as @Amadan explains quite succinctly below :) – ChevCast Commented Sep 16, 2015 at 2:11
1 Answer
Reset to default 9if (e.which == 13 && e.shiftKey)
Shift, Ctrl and Alt are modifier keys, that get their own flags in the event data.
本文标签: javascriptHow to check if 39enter39 key was pressed with 39shift39 key in textareaStack Overflow
版权声明:本文标题:javascript - How to check if 'enter' key was pressed with 'shift' key in textarea - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745481366a2660187.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论