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');
};
});
精彩评论