2013-05-08 45 views
1

我正在形成像下面的運行時彈出一些羊肚菌,但我想應用背景顏色css如何應用它?如何應用jQuery對話框的背景顏色css

$("<div></div>") 
       .addClass("dialog1") 
       .attr("id", $(this).attr("id")) 
       .appendTo("body") 
       // .addCss("background-color","red") 
       .dialog({ 
        title: $(this).attr("data-dialog-title"), 
        close: function() { $(this).remove() }, 
        width: $(this).attr("data-dialog-width"), 
        modal: true, 
        position: 'center', 
        resizable: $(this).attr("data-dialog-resizable") 
       }).load(url); 

       $(".close").live("click", function (e) { 
        e.preventDefault(); 
        // $(this).dialog('destroy').remove(); 
        $(this).closest(".dialog1").dialog("close"); 
       }); 
+1

你嘗試使用'的.css()' – bipen 2013-05-08 09:33:06

回答

3

可以使用css(),而不是addCss

.css("background-color","red") 

以及live()已過時,你應該使用on()代替

+0

如上將被要求在所有地方叫過的位置對話框啓動在網站中,我們可以輕鬆覆蓋所有對話框的CSS。 – 2013-05-08 09:38:31

0

使用.css()

$("<div></div>") 
      .addClass("dialog1") 
      .attr("id", $(this).attr("id")) 
      .appendTo("body") 
      .css("background-color","red") 
      .dialog({ 
       title: $(this).attr("data-dialog-title"), 
       close: function() { $(this).remove() }, 
       width: $(this).attr("data-dialog-width"), 
       modal: true, 
       position: 'center', 
       resizable: $(this).attr("data-dialog-resizable") 
      }).load(url); 

一次使用on(),而不是live()

  $(".close").on("click", function (e) { 
       e.preventDefault(); 
       // $(this).dialog('destroy').remove(); 
       $(this).closest(".dialog1").dialog("close"); 
      }); 

委託它,如果要連接這個動態生成的元素..

$(document).on("click",".close", function (e) { //<--closest static element rather than document 
       e.preventDefault(); 
       // $(this).dialog('destroy').remove(); 
       $(this).closest(".dialog1").dialog("close"); 
      }); 
0

請考慮使用以下代碼:

$("<div></div>") 
    .addClass("dialog1") 
    .attr("id", $(this).attr("id")) 
    .appendTo("body") 
    .css("background-color","red") 
    .dialog({ 
      ... 

重要的是.css("background-color", "red")一行。

0

您可以在css本身中進行更改

例如, .ui-dialog {background:yellow}

0

最簡單的方法是重寫jQuery的對話框背景屬性如下

.ui-dialog .ui-dialog-content { 
     background: red; 
    }