【问题标题】:Mootools .setStyle doesn't change background color in IE9Mootools .setStyle 不会改变 IE9 中的背景颜色
【发布时间】:2013-03-29 10:09:31
【问题描述】:

我有一个 MooTools 脚本,它处理带有按钮的面板(切换面板内容)。

这里是脚本 - 每个按钮设置相应的面板可见 + 改变自己的背景:

buttons.addEvent('mouseenter', function(button){
        var panel = 'panel-' + this.get("id");
        $$('.panel').setStyle('display','none');
        $(panel).setStyle('display','block');
        buttons.setStyle('background',null);
        this.setStyle('background','#183c7c');
    });

对于 IE(在 8 和 9 中尝试),脚本的最后一行不起作用 - 按钮本身的背景没有改变。对于 Firefox 和 Chrome,它可以正常工作。

【问题讨论】:

    标签: css background internet-explorer-9 mootools


    【解决方案1】:

    它在 IE9 下为我工作:http://jsfiddle.net/EWUeP/

    html:

    <div id="divy"></div> 
    

    css:

    div{
        width:300px;
        height: 300px;
        background-color: #eee000;
    }
    

    js:

    var d = document.id('divy');
    d.setStyle('background','#183c7c');
    

    但是,如果您只想更改 bg 颜色 - 调用正确的 css:d.setStyle('background-color','red'); 背景规则是所有背景 css 类型的全局规则 [color url position repeat etc..]

    【讨论】:

    • 忘了提-我也尝试过背景颜色,但当时它也在 Chrome 中造成了麻烦。会不会是其他一些 CSS(不是由脚本添加的那些)正在影响样式?你可以看看 joomla.zdenekvanek.cz 吗?您可以在主页上直接看到面板。它适用于 FF 和 CHrome,而不适用于 IE8 和 9。
    • 是的 - 我知道会发生什么 - 在 IE 中,您在那些覆盖背景颜色的 css 中有过滤规则。您需要在悬停时打开或关闭此过滤器
    猜你喜欢
    • 1970-01-01
    • 2014-06-21
    • 2014-04-21
    • 2021-01-23
    • 2011-06-15
    • 2022-06-11
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    相关资源
    最近更新 更多