开发者

Jquery js-hotkeys plugin adding key pressed into input field

开发者 https://www.devze.com 2023-01-23 02:40 出处:网络
I am using js-hotkeys and when I press a hotkey like \"f\", it adds an f to the input field that I pulled开发者_Go百科 up and focus on.

I am using js-hotkeys and when I press a hotkey like "f", it adds an f to the input field that I pulled开发者_Go百科 up and focus on.

Is there anyway for it not to do that?

I also tried this other plugin http://rikrikrik.com/jquery/shortkeys/#download and it doesnt have that issue but then that plugin had other issue.

Thanks


You can prevent the default action using event.preventDefault(), in this case that default action is adding the letter to the textbox, for example:

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

Note: For those of you going WTF?: This is the syntax the plugin adds, it's not the normal .bind() jQuery core syntax.

I suggest you take a look at John Resig's re-write of the jQuery hotkeys plugin here, it's a much more efficient and 1.4.2+ compatible plugin, you can find the readme here.

See it in action here.

0

精彩评论

暂无评论...
验证码 换一张
取 消