Cmd使用javascript输入keyup组合检测 [英] Cmd Enter keyup combination detection using javascript

查看:98
本文介绍了Cmd使用javascript输入keyup组合检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用键盘检测到我的所有表单来检测输入按钮。
这很容易,如果你按下回车并且事件keyCode等于13然后提交表单,那么当你专注于表单的输入时。

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.

但是现在我想要检测Cmd + Enter组合,因为当你专注于textarea时,输入按钮是一个换行符。那么我的检测语句应该如何?

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?

谢谢

推荐答案

你的意思是 ctrl Cmd ?然后检查 event.ctrlKey 是否为真:

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

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

另见这个例子

Ps:还有布尔值 event.altKey for alt event.shiftKey for shift event.metakey

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

这篇关于Cmd使用javascript输入keyup组合检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆