【问题标题】:Jquery js-hotkeys plugin adding key pressed into input fieldJquery js-hotkeys插件将按键添加到输入字段中
【发布时间】:2011-05-03 07:02:03
【问题描述】:

我正在使用 js-hotkeys,当我按下像“f”这样的热键时,它会在我拉起并关注的输入字段中添加一个 f。

有没有办法让它不那样做?

我也试过这个其他插件http://rikrikrik.com/jquery/shortkeys/#download,它没有那个问题,但是那个插件有其他问题。

谢谢

【问题讨论】:

    标签: jquery keyboard keyboard-shortcuts


    【解决方案1】:

    您可以使用event.preventDefault() 阻止默认操作,在这种情况下,默认操作是将字母添加到文本框,例如:

    $(document).bind('keydown', 'f', function(e) {
      $("input").focus();
      e.preventDefault();
    });
    

    注意:对于那些想玩 WTF 的人?:这是插件添加的语法,它不是正常的 .bind() jQuery 核心语法。

    我建议你看看John Resig's re-write of the jQuery hotkeys plugin here,它是一个更高效且兼容1.4.2+ 的插件you can find the readme here

    See it in action here.

    【讨论】:

    • 啊,尼克又帅了。实际上我正在使用约翰的重写,它有问题。但是你的建议解决了它。似乎是插件上的一个错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    相关资源
    最近更新 更多