如何更换浏览器短键默认值 [英] how to replace browser short keys defaults

查看:141
本文介绍了如何更换浏览器短键默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

但我想定义一个快捷键...

but I want to define a short key...

一种方法是使用绑定()功能jQuery的,问题是,键的默认工作仍在工作。 即:CTRL + S = savepage

one way is to use bind() function in jquery, and the problem is, keys default job is still working. i.e: Ctrl+s = savepage

任何解决方案?

推荐答案

在链接的问题是不正是你要找的,但也可以使用相同的概念。下面是jQuery的只相当于监听按Ctrl + S

The question you linked isn't exactly what you were looking for, but the same concept can be used. Here's the jQuery equivalent only listening for Ctrl+s

$(document).on("keydown",function(e){
    if (e.originalEvent.ctrlKey && e.which == 83/*"s"*/) {
        setTimeout(function(){ //Fix for firefox. Ref: http://stackoverflow.com/questions/14860759/cant-override-ctrls-in-firefox-using-jquery-hotkeys
            // do save stuff...
            alert("Saved!"); // if you remove alert, you can remove setTimeout
        },0);
        return false;
    }
});

http://jsfiddle.net/SEQVD/3/

测试在Chrome,火狐和IE。

Tested in Chrome, Firefox, and IE.

这篇关于如何更换浏览器短键默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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