jQuery热键和CTRL-C [英] jquery hotkeys and CTRL-C
问题描述
我正在构建一个Webapp,用户可以在其中单击表中的任何单元格.单击时,将复制该单元格的文本,并将在弹出式菜单中禁用的textarea中弹出该文本,并在js中选择了textarea.然后邀请用户按CTRL-C复制现在在选定文本区域内的文本.
I am building a webapp where a user can click on any cell in a table. On click, the text of that cell is copied and will pop up inside a disabled textarea in a fancybox, and the textarea is selected in js. The user is then invited to hit CTRL-C to copy the text that is now inside the selected textarea.
当CTRL-C发生时,我想将两件事结合在一起: (1)复制所选文字 (2)关闭fancybox
I would like to combine 2 things together when CTRL-C happens: (1) Copy the selected text (2) Close the fancybox
我可以使用jquery热键来捕获CTRL-C,但是一旦我使用它来调用fancybox close方法,该事件就不再传播了.无论如何都可以使用两者.我的代码是:
I can trap the CTRL-C using jquery hotkeys, but once I use that to call the fancybox close method, the event is no longer propagating. is there anyway to use both. My code is:
$(document).bind('keydown', 'ctrl+c', function(event){
$.fancybox.close(); // if this is commented out, CTRL-C works just fine
return true;
});
我已经多次解释了这个问题与其他问题的不同之处.我在最初的问题中表示可以检测到击键.问题是如何检测到这一点,让该动作继续进行,并采取另一种动作.我在下面提供了一个答案,我自己弄清楚了.
I have explained numerous times how this question is different from the others. I indicated in my original question that I can detect the keystrokes. The problem was how to detect that, let the action continue and also to take another action. I provided an answer below, which I figured out on my own.
推荐答案
<textarea>test</textarea>
<p id="test"></p>
$(document).keydown(function(e) {
if (e.keyCode == 67 && e.ctrlKey) {
/* close fancybox here */
$("#test").text("copied!"); /* optional */
}
});
这篇关于jQuery热键和CTRL-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!