1

我有一个应用了class = "dialog-error"的 div 。在 jQuery 中,我为这个 div 分配了一个对话框,如下所示:$('.dialog-error').dialog({});

我希望能够仅定位和修改属于我的“对话框错误”类的 ui 类,所以我尝试了:

.dialog-error .ui-dialog-titlebar {
    background-color: red;
    background-image: none;
    color: white;
    font-size:small;
}
.dialog-error .ui-dialog-buttonpane { 
    font-size: 0.8em; 
} 

但没有一个适用。如何仅针对属于我的类的 UI 类?

我想要实现的是至少有两个不同的类别(如:错误对话和成功对话),并通过更改 div 的类来回切换。非常感谢。

jQuery代码:

$('.dialog-error').dialog({
                resizable: false,
                height: 200,
                width: 350,
                modal: true,
                dialogClass: "dialog-error", //use this to affect the css 
                title: "Missing Information!",
                buttons: {
                    "Back": function() {
                        $(this).dialog("close");
                    }
                }

            });

HTML 代码:

<div class = "dialog-error" style = "display:none;"></div>

按照建议添加了'dialogClass: "dialog-error"'行,但现在根本不会显示 ui 对话框。

4

1 回答 1

2

如果我记得很清楚,jQuery UI 首先会从 DOM 中删除您的 div,然后它会创建一个新的 div 并将原来的放在内容区域中。您的 CSS 类不适用,因为您的 div对话框内,而不是包装它

为了满足您的要求,请尝试在初始化模式时设置dialogClass选项。

见:http ://api.jqueryui.com/dialog/#option-dialogClass

于 2013-08-15T19:43:36.547 回答