MVC3的jQuery keyup事件 [英] MVC3 jQuery keyup event
本文介绍了MVC3的jQuery keyup事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个C#.NET MVC3 Web应用程序,我想陷阱的关键事件上的文档。也就是说,我想知道,如果usre选择了CTL-> Z撤消在网络上查看其数据的变化。我怎么可以这样做?
I have a C#.NET MVC3 web app and I want to trap the key up event on the document. Namely, I want to know if the usre has selected "CTL->Z" to undo their data changes on the web View. How might I do this?
推荐答案
我觉得这是你在找什么:
I think this is what you're looking for:
var ctrlDown = false;
$(document).keydown(function (e) {
if (e.which == 17)
ctrlDown = true;
if (e.which == 90)
if (ctrlDown)
console.log("control Z");
});
$(document).keyup(function (e) {
if (e.which == 17)
ctrlDown = false;
});
修改
我不知道,如果从mesiesta的回答e.ctrlKey支持跨浏览器的,但如果是这样,你可以做更简单的:
I'm not sure if e.ctrlKey from mesiesta's answer is supported cross-browser, but if it is, you could do more simply:
$(document).keydown(function (e) {
if (e.which == 90 && e.ctrlKey)
console.log("control Z");
});
这篇关于MVC3的jQuery keyup事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文