问题描述
|
我正在尝试将Ctrl + t组合键与某个事件绑定,因此,如果我在应用程序中按Ctrl + t,则应转到指定的url。如何使用Jquery呢?
解决方法
查看jQuery HotKeys插件:
http://plugins.jquery.com/project/hotkeys
更新:
新增范例
<html>
<head>
<script src=\"jquery-1.3.2.min.js\"></script>
<script src=\"jquery.hotkeys.js\"></script>
<script>
$(document).ready(function(){
$(document).bind(\'keydown\',\'Ctrl+t\',function(event){ alert(\'Ctrl t pressed\')});
});
</script>
</head>
<body>
</body>
</html>
, 您可以使用keydown
,event.which
和event.ctrlKey
非常简单地执行此操作。这些已由jQuery标准化,因此您无需大惊小怪地整理跨浏览器的内容。
$(document).keydown(function(event) { // or whatever selector
if (event.ctrlKey && (event.which === 84)) {
window.location = \'http://example.com\'; // or whatever url
}
});
, 尝试这个:
var isCtrl = false;
$(document).keyup(function(e) {
if (e.which == 17) isCtrl = false;
}).keydown(function(e) {
if (e.which == 17) isCtrl = true;
if (e.which == 84 && isCtrl == true) {
window.open(\'http://www.google.com\',\'_self\',\'resizable,location,menubar,toolbar,scrollbars,status\');
return false;
}
});
, <html>
<head>
<script src=\"jquery-1.3.2.min.js\"></script>
<script src=\"jquery.hotkeys.js\"></script>
<script>
$(document).ready(function(){
function test(evt){
var keyCode = (evt.which?evt.which:(evt.keyCode?evt.keyCode:0))
if(keyCode==116)
window.location.href=\'your redirection\';
}
});
</script>
</head>
<body>
<input type=\"Text\" onkeypress=\" test(event);\"
</body>
</html>