javascript - 用 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;
}
}
});
解决方案
这确实是不可能的。
我这样做的地方是在 OS X 上使用命令键(test for .metaKey()
),在 Windows 上使用 ctrl。
推荐阅读
- material-ui - 更新到 v4 后自定义样式中断
- javascript - 仅当在 chrome 中打开开发工具时,catch 块内的 Javascript 'alert' 功能才有效
- stripe-payments - 无法解析来自 stripe cli 的 webhook 签名秘密
- css - 在 vue 中对抗单页应用程序中无样式文本的闪烁
- java - 任何人都可以确认 ExpressJS 比 Spring Boot 慢吗?
- asp.net-web-api - HTTP 端点/URI 如何与它调用的 WebAPI 相关
- c - 从文件读取不会返回任何内容,但会被访问
- javafx - Javafx TilePane PrefColumns
- ruby-on-rails - 会话控制器的 Rspec
- go - 如何在错误前添加字符串?