使用 jquery(而不是 css)打开 jqueryui 对话框后更改对话框颜色



我正在尝试在打开 jqueryui 对话框后更改其背景。 要求阻止我在样式表中设置它,因为背景颜色或图像对于单击链接的人来说是唯一的(背景值是从数据库中提取的)。

当我在加载对话框后运行以下 jquery 命令来更改div 的 css 时,它不执行任何操作?

$("#modal_popup_website").css("background","red !important");

$("#modal_popup_website .ui-dialog-content").css("background","red !important");

$(".ui-dialog-content").css("background","red !important");

我做错了什么?

首先,我按如下方式初始化对话框:

$("#modal_popup_website").dialog({
            bgiframe: true,
            autoOpen: false,
            position: 'center',
            width: $(window).width()-30,
            minWidth: 990,
            height: 900,
            minHeight: 900,
            modal: true,
            stack: true, //Puts in front of other dialog's that may be open
            open: function(){
            },
            close: function() {
                //Save
            }

然后,当用户单击如下链接时,我打开对话框:

$("#modal_popup_website").dialog("open");

打开后,我将一些 HTML 放入对话框中,如下所示:

$("#modal_popup_website").html('gets loaded from external file');

下面是外部文件的 HTML:

<div>some text</div>
<script type="text/javascript">
   $("#modal_popup_website").css("background","red !important");
</script>

<脚本>区域是我尝试更改 css 背景的地方。 在外部PHP文件中,我从数据库中检索该用户的背景颜色或图像,我想更改对话框的背景,但我无法使其工作。

任何想法将不胜感激!

谢谢。

这需要更改:

<div>some text</div>
<script type="text/javascript">
   $("#modal_popup_website").css("background","red !important");
</script>

自:

<script type="text/javascript">
    $(document).ready(function() {
        $("#modal_popup_website").css("background","red");
    });
</script>

此链接应该有帮助:http://css-tricks.com/when-using-important-is-the-right-choice/

我最终以另一种方式解决了这个问题。 我添加了另一个

,并使其 100% 宽,100% 高,并使用 css 背景添加图像。 然后我删除了 jqueryui 对话框的滚动条,只是将 overflow:auto 添加到我添加的新div 中,它给了我需要的东西。

最新更新