gpt4 book ai didi

javascript - 使用 jquery 禁用特定功能键

转载 作者:行者123 更新时间:2023-11-30 18:45:50 25 4
gpt4 key购买 nike

我想在我的网页上禁用 F8 键。有什么方法可以使用 jquery 或任何关联的插件或仅使用 javascript 来禁用它?

提前致谢... :)

布拉斯特拉尔弗雷德

最佳答案

像这样Disable F5 key in Safari 4

但使用 keyCode 119:

<script>
var fn = function (e)
{

if (!e)
var e = window.event;

var keycode = e.keyCode;
if (e.which)
keycode = e.which;

var src = e.srcElement;
if (e.target)
src = e.target;

// 119 = F8
if (119 == keycode)
{
alert('nope')
// Firefox and other non IE browsers
if (e.preventDefault)
{
e.preventDefault();
e.stopPropagation();
}
// Internet Explorer
else if (e.keyCode)
{
e.keyCode = 0;
e.returnValue = false;
e.cancelBubble = true;
}

return false;
}
}
document.onkeypress=document.onkeydown=document.onkeyup=fn
</script>

关于javascript - 使用 jquery 禁用特定功能键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5540549/

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