2014-06-28 54 views
0

下面的演示頁面代碼。我做了一個聰明的通知。我可以看到,在CSS中,它被設置爲背景黑色,我嘗試在創建時動態地將其更改爲不同的顏色,當我在檢查器中執行此操作時工作,但不在代碼中。任何幫助表示讚賞(我基本上試圖使它的黑色初始通知隨機顏色)。動態更改通知背景

// With Input 
    $('.MessageBoxContainer').css({backgroundColor: 'red'}); 
    // This is what I try to change colour, des not work 

    $.SmartMessageBox({ 
     title : "Welcome to the Clevertree demonstration.", 
     content : "Please enter your name to continue", 
     buttons : "[Accept]", 
     input : "text" 


    }, 



     function(ButtonPress, name) { 
     //alert(Value); 
     $(".chosen_name").html(name); 

     $.ajax({ 
      'url' : 'http://clevertree.co.uk/index.php/site/blankadd', 
      'type' : 'POST', //the way you want to send data to your URL 
      'data': { 
       name: name 
      }, 
      'async': false, 
      'success' : function(data){ //probably this request will return anything, it'll be put in var "data" 
       if(data){ 

        userInfo = jQuery.parseJSON(data); 
        //userInfo.User_ID 
        //alert(userInfo.User_ID); 

        $('.MessageBoxContainer').css({backgroundColor: 'red'}); 
    // I try again here, still does not work 
       } 

      } 
     }); 

回答

0

您可以編寫象下面這樣改變CSS顏色

$('.MessageBoxContainer').css('background-color','yellow'); 

在這裏看到的jsfiddle: http://jsfiddle.net/24XE2/3/

你能粘貼HTML以及

+0

感謝。這是所有的代碼真的要生成對話框。我不會在HTML中調用任何東西。上面的代碼在頁面加載時自動調用。我可以在javascript中改變它的顏色,而不用編輯CSS(因爲我還想要一些黑色的)? – user1149620