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

后端 未结 14 1286
不思量自难忘°
不思量自难忘° 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 17:13
    $("#logonDialog").keydown(function (event) {if (event.keyCode == 13) {
            $(this).parent().find("button:eq(0)").trigger("click");
            return false;
        }
    });
    
    0 讨论(0)
  • 2020-12-04 17:13

    This simple piece of code styles your buttons and sets the default to the last one:

     open: function(){
    
          $buttonPane = $(this).next();
          $buttonPane.find('button:first').addClass('accept').addClass('ui-priority-secondary');
          $buttonPane.find('button:last').addClass('cancel').addClass('ui-state-default');
          $buttonPane.find('button:last').focus();
    
      },
    
    0 讨论(0)
提交回复
热议问题