[英]jquery ui - making dialogs more “dynamic”?
I have a page that uses multiple dialogs for different things. 我有一个页面,使用多个对话框来处理不同的事情。 Some dialogs may have buttons that others do not while other may need to be a different height than another... All of them have a set of params that will not change.
有些对话框可能有其他人没有的按钮,而其他对象可能需要与另一个高度不同......所有这些按钮都有一组不会改变的参数。 My question, can I have a default like:
我的问题,我可以有一个默认值:
$('.someElement').dialog({
width: 999,
show: 'slide',
hide: 'slide',
ETC: 'some other option'
});
and use it for all of my dialogs, then pass buttons or height to it dynamically when I open a dialog? 并将其用于我的所有对话框,然后在打开对话框时动态地将按钮或高度传递给它? It just seems wrong to have something like the above for every dialog I need...
对于我需要的每个对话框都有类似上面的内容似乎是错误的...
Thanks! 谢谢!
You could create a wrapper function for this: 您可以为此创建一个包装函数:
function showDialog(target, options){
options.width = 999;
options.show = 'slide';
options.hide = 'slide';
$(target).dialog(options);
}
And then you would just call the function when you want to create a dialog. 然后,您只需在要创建对话框时调用该函数。 You could even get fancy and turn it into a jQuery plugin if you really want to...
如果你真的想要......你甚至可以把它变成jQuery插件
You can use the "option"
method (which takes an object, of the same format), like this: 您可以使用
"option"
方法 (它采用相同格式的对象),如下所示:
$('.someElement').dialog({
width: 999,
show: 'slide',
hide: 'slide',
autoOpen: false
});
$('.someElement').dialog('option', {
buttons: { "Ok": function() { $(this).dialog("close"); } },
height: 400
}).dialog('open');
You can see a demo here , this just sets whatever options you want before calling the open
method . 你可以在这里看到一个演示 ,这只是在调用
open
方法之前设置你想要的任何选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.