jQuery Prevent默认操作功能键(F3,F4等) [英] jQuery Prevent Default Action Function Keys (F3, F4, etc.)

查看:118
本文介绍了jQuery Prevent默认操作功能键(F3,F4等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个非常基本的示例: http://jsfiddle.net/arhVd/1/

I have this extremely basic example here: http://jsfiddle.net/arhVd/1/

<form>
  <input type="text">
  <input type="submit">
</form>

$(function () {

    $(document).keydown(function(e) {

        e.preventDefault();

        $('form').submit();
    });
});

我想确保按F4时不执行内置的浏览器功能(在F4的情况下,将焦点设置为URL栏.或者F3显示查找"栏.)提交表单的功能仍然有效,我只是不希望浏览器功能受阻.

I want to ensure that when pressing F4 it does not do the built in browser function (in F4's case set focus to the URL bar. Or perhaps F3 showing the 'Find' bar.) The functionality of submitting the form still works, I just don't want the browser functionality getting in the way.

这是针对内部应用程序的,功能键应该可以在应用程序中具有热键.

This is for an internal app where the function keys are supposed to function has HotKeys in the app.

推荐答案

这似乎适用于IE8中的F3:

This seems to work for F3 in IE8:

$(document).keydown(function(event) {
  event.preventDefault();

  if (event.keyCode == 114) { // F3
    // Remap F3 to some other key that the browser doesn't care about
    event.originalEvent.keyCode = 0;
  }
};

(基于 http://www.fixya.com/support/t218276-disable_f3_function_key_from_intenet)

这篇关于jQuery Prevent默认操作功能键(F3,F4等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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