无法更改下拉菜单的背景颜色

时间:2014-01-20 12:15:07

标签: html css colors

我正在更改像(蓝色,灰色)这样的主题,这个主题工作得非常好,当我的主题发生变化时,我还想更改下拉菜单背景颜色,现在是#333。 任何帮助将不胜感激。

css:
----
.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus,.dropdown-submenu:hover>a,.dropdown-submenu:focus>a
{

    text-decoration:none; 
    color:#ffffff; 
    background:#333;
}

#photo
{
    float: left;
    width: 40px;
    height: 40px;
    border: 1px solid #cfcfcf;
    background: #031;
}


javascript:
-----------

function switchTheme(themename) 
{
    var cookieInfo = "theme = " + themename;
    document.cookie = cookieInfo;

    var classes = $("body").prop("class").split(" ");
    _.each(classes, function(c) 
    {
       if (_.string.startsWith(c, 'theme-'))
                $("body").removeClass(c);
    });

    $("body").addClass(themename);

    var color = '#031';
    if(themename == 'theme-grey')
    {
        color = '#333';
    }
    else if(themename == 'theme-blue')
    {
        color = '#034';
    }
    document.getElementById('photo').style.background = color; //this works
    document.getElementById('dropdown-menu>li>a').style.background = color; // this is not working. why?
}
</script>

1 个答案:

答案 0 :(得分:0)

您正在使用css表达式来查找具有document.getElementById('dropdown-menu>li>a')

的dom元素