使用jQuery禁用特定功能键 [英] Disable specific function key using jquery

查看:100
本文介绍了使用jQuery禁用特定功能键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网页上禁用F8键.有什么方法可以使用jquery或任何相关插件或仅通过javascript禁用它吗?

I want to disable F8 key on my web page. Is there any way I can disable it using jquery or any associated plugins or just javascript??

预先感谢... :)

blasteralfred

blasteralfred

推荐答案

类似于禁用Safari 4中的F5键

但使用keyCode 119:

but using 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>

这篇关于使用jQuery禁用特定功能键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆