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

后端 未结 14 1283
不思量自难忘°
不思量自难忘° 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:06

    A slight variation to use the buttons name as the selector. It reads a little better but there is obvious duplication with the button text string. Refactor to taste.

    $("#confirm-dialog").dialog({
        buttons: {
            "Cancel" : function(){},
            "OK" : function(){}
        },
        open: function() {
            $(this).siblings('.ui-dialog-buttonpane').find("button:contains('OK')").focus(); 
        }
    });
    

提交回复
热议问题