如何将焦点放在ASP.NET MVC页面上的JQuery Dialog按钮之一?

Rit*_*ita 5 asp.net-mvc jquery jquery-ui jquery-dialog asp.net-mvc-2

我有一个ASP.NET MVC页面(注册).在加载页面时,我在该对话框上使用" 同意"和" 不同意"按钮调用Jquery Dialog.

1).默认情况下如何将焦点设置为"同意"按钮

2).如何禁用右上角的X(关闭)标记?(因此我不希望用户简单地关闭该对话框).

码:

$("#dialog-confirm").dialog({
        closeOnEscape: false,
        autoOpen: <%= ViewData["autoOpen"] %>,
        height: 400,
        width: 550,
        modal: true,
        buttons: {
            'Disagree': function() {
                location.href = "/";
            },
            'Agree': function() {
                $(this).dialog('close');
                $(this).focus();
            }
        },
        beforeclose: function(event, ui) {
            var i = event.target.id;
            var j = 0;
        }
    });        
Run Code Online (Sandbox Code Playgroud)

感谢您的回复.

谢谢

小智 11

我用这个:

$("#dialog-confirm").dialog({

     open: function(event, ui) {

          $(".ui-dialog-titlebar-close").hide(); // Hide the [x] button

          $(":button:contains('Ok')").focus(); // Set focus to the [Ok] button
     }

});
Run Code Online (Sandbox Code Playgroud)