0
我有一個web應用程序,我正在努力,我希望用戶能夠動態地定義和觸發熱鍵。我希望有人能幫助我?jQuery如何創建和發射動態熱鍵(keycode和:not()selector?)
我用相關的HTML創建了JSFiddle HERE。
這裏是我的javascript:
// Assign Hotkey (this seems to be working)
$('input.hotkey').keydown(function(event) {
var hkey = event.keyCode;
if (hkey == $('span#hk').text()){
alert('This key is already in use');
} else
$(this).parent().parent().prev().find('span#hk').text(hkey);
});
// Fire Hotkey (the problem might be here?)
$(document).not('input').keydown(function (event) {
var hkey = event.keyCode;
if (hkey == $('span#hk').text()){
$("span#hk:contains("+hkey+")").parent().click();
}
});
// Play Selected Track
$('#track').live('click', function() {
// Fake Function
var title = $('#title', this).text();
alert(title + ' is playing...');
});
注:我已經使用了「空間」和「左/右」方向鍵爲全局熱鍵 - 是爲了保護/防止它們被分配的一種方式?
是否有比使用.not('input')更好的選擇器來防止在輸入打字期間觸發軌道?
感謝您的幫助!
非常感謝!這對於輸入/文檔事件的定位非常出色! – Josiah 2011-05-14 19:50:33