开发者

js-hotkeys - how to bind to the ? question mark

I've been using js-hotkeys for a while, love it.

I'd now like to bind to the ? key, but that doesn't appear to be supported. Anyone know why and how to 开发者_StackOverflowbind to the ? question mark?

$(document).bind('keydown', '?',function (evt) {
    alert('go');
});

The above code does not work.


What about

$(document).bind('keyup', function (evt) {
    if (evt.keyCode == 191)
       alert("go");
});


I believe the event has a flag for whether the shift key was pressed, so you probably want to do something like this (i've never used js-hotkeys, so I may be completely wrong):

$(document).bind('keydown', '/', function (evt)
{
  if (evt.shiftKey) //or whatever the flag for the shift key may be
  {
    alert('go');
  }
});


Beware that the following will trigger even inside of an input box:

$(document).bind('keyup', function (evt) {
    if (evt.keyCode == 191)
       alert("go");
});

Solution:

$(document).bind('keyup', function(e) {
    if(e.keyCode === 191 && !$(e.target).is("input")) 
        alert("go");
});

Keep in mind that the same thing will happen for texarea.


Using js-hotkeys, you would bind the Question Mark using the string:

shift+/
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜