jquery - 动态更改通知背景

标签 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
                }

            }
        });

最佳答案

你可以像下面这样写来改变css颜色

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

在这里查看 jsfiddle: http://jsfiddle.net/24XE2/3/

你能把你的html也贴上来吗

关于jquery - 动态更改通知背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24467617/

相关文章:

Android - 通知 PendingIntent 转到错误的 Activity?

rspec - 如何关闭新输出的 iTerm2 growl 通知,但保留它们用于 rspec 结果

javascript - 使用 jQuery 的复选框

javascript - 函数在 Javascript 中不起作用

javascript - 选择:update not working in $. ajax成功调用

php - 以编程方式包含条件(特定于浏览器)样式表

javascript - jquery.mobile 滑动页面导航限制为 div 元素

html - 在移动设备上将固定内容隐藏在 div 后面

html - 在 CSS 下拉菜单中单击后,从链接中删除焦点

ios - APNs 消息发送到服务器,设备 iOS 上没有通知