如何检查是否在textarea中使用'shift'键按下了'enter'键

时间:2015-09-16 02:04:40

标签: javascript jquery keypress shift enter

我知道shift key代码为16enter key代码为13

//@ catching any 'enter' keypress in textarea.
    function textareaOnEnter(){
        $('textarea#someId').keypress(function(e)
        {
          if(e.which == 13)
          {
            //.. works only for 'enter'
          }
        });     
    }

我认为这可能就像这样简单:

    function textareaOnShiftAndEnter(){
        $('textarea#someId').keypress(function(e)
        {
          if(e.which == 13 && e.which == 16)
          {
            //.. don't work for nothing
          }
        });     
    }

但当然它根本无法正常工作。如何查看shift + enter按键?

1 个答案:

答案 0 :(得分:5)

if (e.which == 13 && e.shiftKey)

Shift,Ctrl和Alt是修饰键,它们在事件数据中获得自己的标记。