使用JQuery捕获CTRL + S的最佳跨浏览器方法? [英] Best cross-browser method to capture CTRL+S with JQuery?
本文介绍了使用JQuery捕获CTRL + S的最佳跨浏览器方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的用户希望能够点击 Ctrl + S 来保存表单。是否有一种良好的跨浏览器方式来捕获 Ctrl + S 组合键并提交我的表单?
My users would like to be able to hit Ctrl+S to save a form. Is there a good cross-browser way of capturing the Ctrl+S key combination and submit my form?
应用程序基于Drupal构建,因此jQuery可用。
App is built on Drupal, so jQuery is available.
推荐答案
$(window).keypress(function(event) {
if (!(event.which == 115 && event.ctrlKey) && !(event.which == 19)) return true;
alert("Ctrl-S pressed");
event.preventDefault();
return false;
});
密码可能因浏览器而异,因此您可能需要检查的不仅仅是115。
Key codes can differ between browsers, so you may need to check for more than just 115.
这篇关于使用JQuery捕获CTRL + S的最佳跨浏览器方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文