Javascript捕获ctrl + alt + c [英] Javascript capturing ctrl+alt+c

查看:135
本文介绍了Javascript捕获ctrl + alt + c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网络应用中,我想使用 ctrl + alt + c 作为热键。

In my web app I want to use ctrl+alt+c as hotkey.

我阅读了一堆Stack Overflow文章并提出了以下解决方案

I read bunch of Stack Overflow articles and came up with below solution

$(document).keydown(function(e){
   if(e.ctrlKey && e.altKey && e.which == 99){
     e.preventDefault();
     window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
   }
});

这不适用于chrome。我试过调试。

This is not working in chrome. I tried debugging.

我注意到的是,只要我按下ctrl键它就会进入功能状态,好像条件失败就会出来。

What I noticed is as soon as I press ctrl key it goes into function and as if condition fails it is coming out.

如何让它工作。

推荐答案

你的代码有两个错误

1st : keycode of c is 67
2nd : text variable is undefined.

所以最终的代码是

$(document).keydown(function(e){
   if(e.ctrlKey && e.altKey &&  e.which == 67){
      e.preventDefault();
       prompt("Copy to clipboard: Ctrl+C, Enter","text");
   }
  });

你可以检查小提琴这里

这篇关于Javascript捕获ctrl + alt + c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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