如何替换浏览器短键默认值

根据一些问题,我发现如何防止我们的组合键。

但我想定义一个短键……

一种方法是在jquery中使用bind()函数,问题是,键默认作业仍然有效。 ie: Ctrl+s = savepage

任何解决方案

您链接的问题并不完全是您所寻找的问题,但可以使用相同的概念。 这是jQuery等效的只听取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,Firefox和IE中测试过。

请确保绑定到快捷方式的事件包含preventDefault。 在jquery中,这应该是这样的:

 function event(e) { e.preventDefault(); } 

使用其他框架,这可能与e.stop()e.stopEvent()