开发者

How to set jQuery UI dialog defaults

开发者 https://www.devze.com 2023-02-19 12:08 出处:网络
How do I set the default values for the jQuery UI dialog? For example, this is how I set the defaults in the jQuery UI datepicker:

How do I set the default values for the jQuery UI dialog? For example, this is how I set the defaults in the jQuery UI datepicker:

$.datepicker.setDefaults({ dateFormat: 'dd/mm/yy' });

I couldn't find the开发者_开发技巧 same functionality in the dialog documentation


I found a solution

$.extend($.ui.dialog.prototype.options, { modal: true, width: 650 });


There's no built-in functionality for that AFAIK, but what I usually do is set them myself in a separate hash like this:

var dialog_defaults = {
  autoopen: false,
  buttons: {
    close: function() { $(this).dialog('close'); }
  }
};

Then when I create the dialog, I use jQuery's extend method to make them work, like this:

$('#divvie').dialog(
  $.extend({}, dialog_defaults, {
    autoopen: true
  })
);

The second set of arguments you pass in will overwrite/merge with whatever's in the dialog_defaults variable. Just make sure you put the empty hash ({}) in there, or your defaults will get overwritten, that's bitten me in the past.

0

精彩评论

暂无评论...
验证码 换一张
取 消