如果有人能帮我解决这个问题,我将永远感激不尽。
从本质上讲,focus 函数应该使它成为这样,如果用户按 Enter 键进入对话框中 3 个字段中的最后一个字段之外的任何字段,它就会充当选项卡。如果他们在 LAST 字段中按回车键,它将提交表单。后一个函数有效,但制表符不起作用。
有人知道为什么吗?我没有发布整个代码块,但这应该提供足够的数据。我使用event.target是不是错了?
$('#dialog-add-items').dialog({
autoOpen: false,
resizable: false,
width:500,
position:['center',80],
modal: true,
focus: function() {
$(':input:last', this).unbind('keyup').keyup(function(event) {
if (event.keyCode == 13) {
$('.ui-dialog-buttonpane button:first').click();
}
});
$(':input:not(:last)', this).unbind('keyup').keyup(function(event){
if(event.keyCode == 13){
name=event.target;
$(name).next('input').focus();
}
});
},...
如果我不得不猜测,我会说$('.ui-dialog-buttonpane button:first').click();
是罪魁祸首。尝试为您的按钮提供一个 ID 和引用,如下所示:
$('#dialog-add-items').dialog({
autoOpen: false,
resizable: false,
width:500,
position:['center',80],
modal: true,
focus: function() {
$(':input:last', this).unbind('keyup').keyup(function(event) {
if (event.keyCode == 13) {
$('#okbutton').click();
}
});
$(':input:not(:last)', this).unbind('keyup').keyup(function(event){
if(event.keyCode == 13){
name=event.target;
$(name).next('input').focus();
}
});
},
buttons: [{text: 'Ok', id:'okbutton'}],...
我只是简单地添加了一个 if/else 语句来测试两个字段中的哪一个被聚焦,然后跳到下一个字段。 繁琐而丑陋,但这是我唯一能上班的东西。