jquery-ui Dialog: Make a button in the dialog the default action (Enter key)

后端 未结 14 1308
不思量自难忘°
不思量自难忘° 2020-12-04 16:27

In a jquery modal dialog, is there a way to select a button as the default action (action to execute when the user presses enter)?

Example of jquery web site: jquer

14条回答
  •  悲&欢浪女
    2020-12-04 16:52

    In your dialog's open function, you can focus the button:

    $("#myDialog").dialog({
        open: function() {
          $(this).parents('.ui-dialog-buttonpane button:eq(0)').focus(); 
        }
    });
    

    Change the :eq(0) if it's at a different index, or find by name, etc.

提交回复
热议问题