How to set jQuery UI dialog defaults

时光总嘲笑我的痴心妄想 提交于 2019-12-09 10:08:40

问题


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


回答1:


I found a solution

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



回答2:


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.



来源:https://stackoverflow.com/questions/5409633/how-to-set-jquery-ui-dialog-defaults

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!