Ctrl+Enter jQuery in TEXTAREA

前端 未结 8 617
死守一世寂寞
死守一世寂寞 2020-12-12 13:59

How do I trigger something when the cursor is within TEXTAREA and Ctrl+Enter is pressed? Using jQuery. Thanks

相关标签:
8条回答
  • 2020-12-12 14:58

    first you have to set a flag when Ctrl is pressed, do this onkeydown. then you have to check the keydown of enter. unset the flag when you see a keyup for Ctrl.

    0 讨论(0)
  • 2020-12-12 15:01

    You can use the event.ctrlKey flag to see if the Ctrl key is pressed, something like this:

    $('#textareaId').keydown(function (e) {
    
      if (e.ctrlKey && e.keyCode == 13) {
        // Ctrl-Enter pressed
      }
    });
    

    Check the above snippet here.

    0 讨论(0)
提交回复
热议问题