开发者

Opening jQuery UI dialog with a keyboard shortcut puts the key pressed into the dialog's form

I have a form inside a jQuery UI dialog. The dialog is set to open whenever the "t" key is pressed. The problem is, when this happens, the letter "t" gets inserted into the first input of that dialog's form, which I don't want to happen.

Here's the code I have:

$('#addtime-form').dialog({
  minWidth: 351,
  modal: true,
  autoOpen: false,
  title: 'Add Time',
  resizable: f开发者_StackOverflow社区alse
});

$(document).keypress(function(e){
  if (e.which == 116 || e.keyCode == 116 || window.event.keyCode == 116) {
    $('#addtime-form').dialog('open');
  };
});


Try this:

$(document).keypress(function(e){
  if (e.which == 116 || e.keyCode == 116 || window.event.keyCode == 116) {
    e.preventDefault();
    $('#addtime-form').dialog('open');
  };
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜