在焦点上显示jquery UI对话框不会聚焦元素

时间:2021-09-25 19:46:11

I want to display an jquery UI dialog when a user focues a certain input box. It works the problem is, that the input box won't get the focus after closing the dialog, meaning user clicks into input box, dialog is opened. User closes dialog -> input box does not have focus.

我想在用户聚焦某个输入框时显示一个jquery UI对话框。它的工作问题是,关闭对话框后输入框不会得到焦点,这意味着用户点击进入输入框,打开对话框。用户关闭对话框 - >输入框没有焦点。

The only way to actually focus the input box is ti click into it a second time while the dialog is already displayed. This is pretty annoying. i would like the inputbox to have focus after closing the dialog.

实际聚焦输入框的唯一方法是在对话框已经显示时再次点击它。这很烦人。我希望输入框在关闭对话框后具有焦点。

$(function() {
    $( "#identifiersDialog" ).dialog({autoOpen: false});
});        
$('#identifiers').focus(function(event) {
     $( "#identifiersDialog" ).dialog('open');           
});

2 个解决方案

#1


2  

You could use

你可以用

$(function(){
    InitiliseInput();    
});
function InitiliseInput(){
    $('#identifiers').bind('focus', function() {
        $('#identifiersDialog').dialog({ close: function() { 
            $('#identifiers').unbind('focus').focus().blur(function(){ InitiliseInput()});              
        }});
    }); 
}

Working example here http://jsfiddle.net/RCBQs/1/

这里的工作示例http://jsfiddle.net/RCBQs/1/

The blur function then resets the dialog once the focus has moved away from the input, so that refocusing opens the dialog again.

一旦焦点移离输入,模糊功能就会重置对话框,以便重新对焦再次打开对话框。

#2


-1  

This should help.

这应该有所帮助。

$(function() {
    $( "#identifiersDialog" ).dialog({autoOpen: false, close: function() { $('#identifiers').focus()  }});
});        
$('#identifiers').focus(function(event) {
     $( "#identifiersDialog" ).dialog('open');           
});

#1


2  

You could use

你可以用

$(function(){
    InitiliseInput();    
});
function InitiliseInput(){
    $('#identifiers').bind('focus', function() {
        $('#identifiersDialog').dialog({ close: function() { 
            $('#identifiers').unbind('focus').focus().blur(function(){ InitiliseInput()});              
        }});
    }); 
}

Working example here http://jsfiddle.net/RCBQs/1/

这里的工作示例http://jsfiddle.net/RCBQs/1/

The blur function then resets the dialog once the focus has moved away from the input, so that refocusing opens the dialog again.

一旦焦点移离输入,模糊功能就会重置对话框,以便重新对焦再次打开对话框。

#2


-1  

This should help.

这应该有所帮助。

$(function() {
    $( "#identifiersDialog" ).dialog({autoOpen: false, close: function() { $('#identifiers').focus()  }});
});        
$('#identifiers').focus(function(event) {
     $( "#identifiersDialog" ).dialog('open');           
});