Cmd Enter keyup combination detection using javasc

2019-04-15 11:27发布

I'm using a keyup detection into all my forms to detect the enter button. This is easy, when you are focused in a form's input if you hit enter and the event keyCode is equal to 13 then the form submitted.

But now I want to detect the Cmd + Enter combination, because when you are focused in a textarea, the enter button is a line break. So how my detect statement should look like?

Thank you

1条回答
Rolldiameter
2楼-- · 2019-04-15 12:03

You mean ctrl with Cmd? Then check if event.ctrlKey is true:

if (event.ctrlKey && event.keyCode == 13) {
    alert('now');
}

Also see this example.

P.s: there are also the booleans event.altKey for alt, event.shiftKey for shift and event.metakey

查看更多
登录 后发表回答