我正在尋找一種方法來檢測Cmd的 + [R和Cmd的 + W¯¯(也按Ctrl +[R和按Ctrl +W¯¯)在我的應用程序。通過Javascript檢測cmd + r和cmd + w(以及ctrl + r和ctrl + w)?
This site do it http://gpl.internetconnection.net/vi/。儘管來源是一場噩夢。如果我找不到快速答案,我會仔細研究一下。
有沒有人有鏈接或例子?
我正在尋找一種方法來檢測Cmd的 + [R和Cmd的 + W¯¯(也按Ctrl +[R和按Ctrl +W¯¯)在我的應用程序。通過Javascript檢測cmd + r和cmd + w(以及ctrl + r和ctrl + w)?
This site do it http://gpl.internetconnection.net/vi/。儘管來源是一場噩夢。如果我找不到快速答案,我會仔細研究一下。
有沒有人有鏈接或例子?
最後我做什麼說明如下:http://www.sencha.com/forum/archive/index.php/t-5759.html
完美的作品。
使用jQuery:
$.ctrl = function(key, callback, args) {
var isCtrl = false;
$(document).keydown(function(e) {
if(!args) args=[]; // IE barks when args is null
if(e.ctrlKey) isCtrl = true;
if(e.keyCode == key.charCodeAt(0) && isCtrl) {
callback.apply(this, args);
return false;
}
}).keyup(function(e) {
if(e.ctrlKey) isCtrl = false;
});
};
這摘自:http://www.gmarwaha.com/blog/2009/06/16/ctrl-key-combination-simple-jquery-plugin/
我會建議,如本尼所示,使用框架,如jQuery,用於檢測此類輸入,因爲通常它是瀏覽器相關的,可以使它跨瀏覽器兼容手動執行 – azatoth 2010-06-19 20:42:03
是的,我同意。我也發現這個:http://plugins.jquery.com/project/hotkeys。我使用的是Ext JS,所以我可以按照此處所述使用該框架:http://www.sencha.com/forum/archive/index.php/t-5759.html – 2010-06-19 20:51:01