How to get focus on one of the jQuery Dialog buttons on an ASP.NET MVC page?

I have an ASP.NET MVC (Registration) page. When the page loads, I invoke the Jquery Dialog using Agree and Disagree on this Dialog.

1). How to set the default focus on the "Agree" button ?

2). How to disable the X (Close) icon, which is located in the upper right corner? (So ​​that I do not want the user to just close this dialog).

the code:

$("#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; } }); 

Rate your answers.

thanks

+4
source share
1 answer

I use this:

 $("#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 } }); 
+10
source

Source: https://habr.com/ru/post/1310557/


All Articles