【问题标题】:How to check if 'enter' key was pressed with 'shift' key in textarea如何检查是否在textarea中使用“shift”键按下了“enter”键
【发布时间】:2015-12-12 10:45:10
【问题描述】:

我知道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 按键?

【问题讨论】:

标签: javascript jquery keypress shift enter


【解决方案1】:
if (e.which == 13 && e.shiftKey)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-24
    • 2020-01-21
    • 2022-01-01
    • 1970-01-01
    • 2022-01-03
    • 2020-11-05
    • 2012-02-05
    相关资源
    最近更新 更多