开发者

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

开发者 https://www.devze.com 2023-01-18 10:04 出处:网络
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 dia

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

精彩评论

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

关注公众号