gpt4 book ai didi

javascript - 覆盖 javascript/jquery 中的 CMD+N 或 CTRL+N 快捷键?

转载 作者:行者123 更新时间:2023-11-28 04:22:56 24 4
gpt4 key购买 nike

我正在开发一个网络应用程序,我想覆盖 CTRL+N (windows) CMD+N (mac) 快捷键,这样它们就不会打开新窗口。我想要触发自定义事件。

$(window).bind( 'keydown', function(e) {
if(e.ctrlKey && e.keyCode === 'N'.charCodeAt(0)){
e.preventDefault();
// custom trigger
}
});

感谢您的帮助!

最佳答案

请尝试一下这个

<script>
window.addEventListener('keyup', function(e) {
if (e.keyCode === KeyCode.KEY_RETURN) {
console.log('It was the Return key.');
} else {
console.log('It was any other key.');
}
});
<script>

或者

<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<script>
var pKey;
$(function () {
$(window).keydown(function (e) {
if (e.which == 17) {
pKey = e.keyCode;
}
else {
if (pKey == 17 && e.keyCode == 78) {
e.preventDefault();
console.log(e);
}
}
});
});
</script>
</head>
<body>

<div class="container">
<h2>Well</h2>

<div class="well">Hello G...</div>
</div>

</body>
</html>

关于javascript - 覆盖 javascript/jquery 中的 CMD+N 或 CTRL+N 快捷键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45304750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com