C#.NET MVC3 Webアプリがあり、ドキュメントのキーアップイベントをトラップしたいと思います。つまり、usreが「CTL-> Z」を選択して、Webビューでのデータ変更を元に戻したかどうかを知りたいのです。どうすればこれを行うことができますか?
1501 次
2 に答える
2
私はこれがあなたが探しているものだと思います:
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がクロスブラウザでサポートされているかどうかはわかりませんが、サポートされている場合は、もっと簡単に行うことができます。
$(document).keydown(function (e) {
if (e.which == 90 && e.ctrlKey)
console.log("control Z");
});
于 2011-12-05T20:17:16.470 に答える
1
You can try to use this Ctrl + Key Combination – Simple Jquery Plugin
. I've never tried to use it, but it seems a good solution for that)))
Here is the link
http://www.gmarwaha.com/blog/2009/06/16/ctrl-key-combination-simple-jquery-plugin/
So here is that function code
$.ctrl = function(key, callback, args) {
$(document).keydown(function(e) {
if(!args) args=[]; // IE barks when args is null
if(e.keyCode == key.charCodeAt(0) && e.ctrlKey) {
callback.apply(this, args);
return false;
}
});
};
And then in your code you must write only
$.ctrl('Z', function() {
//What you want to do
});
于 2011-12-05T20:26:07.413 に答える