gpt4 book ai didi

javascript - 有没有办法停止在 IE 中传播键盘快捷键?

转载 作者:行者123 更新时间:2023-11-30 17:43:09 25 4
gpt4 key购买 nike

这是我正在使用的代码和我已经尝试过的方法,它们适用于 Chrome 和 Firefox:

$j(document).on('keydown', function (e) {
if(e.keyCode == 80) {
if(ctrl_key == 'yes') {
do_something();

e.preventDefault();
e.stopPropagation();
e.cancelBubble = true;

}
}
});

$j(document).on('keypress keyup', function (e) {
if(e.keyCode == 80) {
if(ctrl_key == 'yes') {
e.preventDefault();
e.stopPropagation();
e.cancelBubble = true;
}
}
});

这是为了打印功能(ctrl + p)

有什么办法可以阻止这种行为吗?

最佳答案

跨浏览器方法:

$j(document).on('keydown', function (e) {
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
if(e.ctrlKey && key == 80) {
e.preventDefault();
e.stopPropagation();
alert("CTRL + P pressed");
return false;
}
});

测试前需要选中“文档”,点击渲染面板或编辑框http://jsfiddle.net/PTauw/99/

关于javascript - 有没有办法停止在 IE 中传播键盘快捷键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20653286/

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