2011-10-15 42 views
0

jQuery UI主题不错,它们适用于整个文档,但我有一些情况下,必须更改标题栏颜色等对话框的样式。jQueryUI.dialog:重写单个CSS样式属性?

以我jQuery的用户界面的CSS,标题栏是编码:

的.ui-对话框的.ui-对话框的标题栏{填充:.4em 1em的;位置:相对; }

这里是我的javascript:

var $AlertDialog = $('<div"></div>') 
.dialog({ 
    autoOpen: false, 
    title: 'Alert Message', 
    buttons: {Ok: function() {$(this).dialog("close");}} 
});  

function Alerter(cTxt) 
{ 
    $AlertDialog.html(cTxt); 
    $AlertDialog.css('ui-dialog-titlebar','color: red'); 
    $AlertDialog.dialog('open'); 
}; 

警报器(),然后调用作为警报的替代品()。

访问和更改'ui-dialog-titlebar'的颜色属性不起作用。

在这个问题之前有大量的阅读。似乎其他人也有类似的问题,但不特定于jQuery UI。

这怎么办?


更新:

多亏了一个很好的提示,我这样做:

$AlertDialog.dialog('open'); 
$("#.ui-dialog .ui-dialog-title").css('color','red'); 
$("#.ui-dialog .ui-dialog-title").css('background-color','orange'); 

作品。但可接受的做法?

+1

为什么不添加一个类并使用CSS设计它? – meleyal

回答

0

首先,

根据documentation的CSS()采用属性作为PARAM。
看来你正在尝试改变ui-dialog-titlebar。而是试试这个:

... 
function Alerter(cTxt) 
{ 
    $AlertDialog.html(cTxt); 
    $AlertDialog.dialog('open'); 
    $(".ui-dialog .ui-dialog-title").css('color','red'); 
    $(".ui-dialog .ui-dialog-title").css('background-color','orange'); 
    //Assuming you want to change header color only 
    //see the theming structure at http://jqueryui.com/demos/dialog/#theming 
}; 
+0

$ moguzalp您提供了一个很好的提示。使用> span产生了一个错误,但我以另一种方式得到了它。 –

+0

$ AlertDialog.dialog('open'); (“#。ui-dialog .ui-dialog-title”).css('color','red'); (“#。ui-dialog .ui-dialog-title”).css('background-color','orange'); –

1

我的建议是不使用.ui-对话框选择器,因为页面上可能有多个对话框。你可以遍历标题栏。

... 
    $AlertDialog.html(cTxt); 
    // might as well use the theme since its part of jquery ui 
    $AlertDialog.prev().addClass("ui-state-error"); 
    $AlertDialog.dialog('open');