jQuery UI 对话框 - 设置默认配置
我有几个 jQuery UI 对话框处理程序,所有这些处理程序都包含以下内容:
open: function(event, ui) {
$(".ui-dialog-titlebar").removeClass("ui-corner-all");
$(".ui-dialog").removeClass("ui-corner-all");
},
这是为了使对话框具有方角,而不是圆角。我想知道是否可以将此设置为默认值,这样我就不必将此代码插入到页面上的每个对话框配置中。
我知道我可以编辑 CSS,但如果不需要的话,实际删除该类更有意义。
I have several jQuery UI Dialogs handlers, all of which contain the following:
open: function(event, ui) {
$(".ui-dialog-titlebar").removeClass("ui-corner-all");
$(".ui-dialog").removeClass("ui-corner-all");
},
This is so that the dialog has square corners, rather than round ones. I was wondering if it's possible to have this set as default, so that I don't have to insert this code into every dialog config on the page.
I know I can edit the CSS, but it makes more sense to actually remove the class if it's not needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道它并不完美,但您可以定义自己的包含默认值的
defaults
对象。然后,如果您需要覆盖或添加这些默认值,您可以使用$.extend
:另请记住,对于事件,您可以使用
on< 绑定到选项对象外部的它们/code> (或其兄弟
delegate
、bind
和live
)。您可以通过将相同的类应用于所有对话框来将该事件处理程序应用于多个对话框,例如:请记住,该事件处理程序不会为新对话框触发。您可以让事件在 DOM 中冒泡到
body
并在那里附加事件处理程序(这是我要走的路线):使用这种事件委托方法,您可以应用您的
open
函数适用于将附加到document.body
的所有对话框。I know it's not perfect, but you could define your own
defaults
object that contains your defaults. Then if you need to override or add to those defaults, you could use$.extend
:Also remember that for the events, you can bind to them outside of the options object by using
on
(or its siblingsdelegate
,bind
, andlive
). You can apply that event handler to multiple dialogs by applying the same class to all of your dialogs, for example:Just keep in mind that this event handler won't fire off for new dialogs. You could let the event bubble up the DOM to the
body
and attach the event handler there (this is the route I would go):With this method of event delegation, you are applying your
open
function to all dialogs that will ever be appended todocument.body
.