Cause analysis and solution of JQuery Dialog dialog box can not be closed through Esc

  • 2021-07-12 04:45:56
  • OfStack

Background: I want to close the Dialog dialog box in the exhibition through Esc key, and find that some dialog boxes can and some will fail.

Cause analysis:

1. Tag elements that can input content on the dialog box can, otherwise not.

2. If the mouse clicks the dialog box, it can also be closed by Esc key.

It can be seen that the dialog box needs to be focused.

Solution:

Option 1:


focus : function(){
    $("#id").focus();
}

Option 2:

Delayed focusing


setTimeout(function() {
    $("#id").focus();
}, 500);

Related articles: