动态更改通知背景

时间:2014-06-28 14:07:46

标签: jquery css notifications

下面的演示页面代码。我做了一个聪明的通知。我可以看到在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
                }

            }
        });

1 个答案:

答案 0 :(得分:0)

您可以像下面这样写更改css颜色

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

请在此处查看jsfiddle: http://jsfiddle.net/24XE2/3/

你也可以粘贴你的HTML吗