首页 > 解决方案 > 用 jquery 覆盖 ctrl-arrows

问题描述

我正在尝试将 ctrl-right 和 ctrl-down 用于浏览器应用程序。在 OS X 中,这会导致一个桌面向右移动或平铺当前桌面上的所有窗口。我正在尝试使用e.preventDefault();,但它不起作用;操作系统功能仍在发生。有没有办法覆盖这些功能?

$(document).keydown(function(e) { //For any other keypress event
  if (e.which == 39) { //Checking if it's right arrow
    if(ctrlPressed == true){
        //spread score across kid's standards
        e.preventDefault();
        var kid = $(':focus').attr('kidid');
        var score = $(':focus').val();
        $('.SmallInput[kidid='+kid+']').each(function(index) {
        ScoreEntry($(this),score);
    });
    ctrlPressed = false;
  }
  } else if (e.which == 40) { //down arrow
    if(ctrlPressed == true){
        e.preventDefault();
        //spread score down standard - all kids
        var std = $(':focus').attr('stdid');
        var score = $(':focus').val();
        $('.SmallInput[stdid='+std+']').each(function(index) {
        ScoreEntry($(this),score);
    });
    ctrlPressed = false;
    }
  }
});

标签: javascriptjquery

解决方案


这确实是不可能的。

我这样做的地方是在 OS X 上使用命令键(test for .metaKey()),在 Windows 上使用 ctrl。


推荐阅读