简体   繁体   English

IE和Edge无法为CSS更改运行Javascript

[英]IE and Edge fail to run Javascript for css change

I've made a simple script to change the color of a div with the class '.logged_inn_text'. 我已经编写了一个简单的脚本,用于使用“ .logged_inn_text”类更改div的颜色。 The script works by taking the background style from the clicked link and inserting it to the class. 该脚本通过从单击的链接中获取背景样式并将其插入到类中来工作。

The code was made in Chrome and it worked perfectly fine, while in IE and Edge nothing happens. 该代码是在Chrome浏览器中完成的,并且运行良好,而在IE和Edge中则什么也没有发生。 If I alert the var named color, there is no response. 如果我alert名为color的var,则没有响应。 Is there a reasonable reason why it's not working? 有什么合理的原因为什么它不起作用?

$(document).ready(function() {
    $('.settings_color_btn').click(function() {
        var colorId = $(this).attr('id');
        var colorIdFull = '#'+colorId;
        var color = $(colorIdFull).css('background');
        $('.logged_inn_text').fadeTo('fast', 0.4, function() {
            $(this).css('background', color);
        }).fadeTo('fast', 1);
        return false;
    });
});

Seems IE return undefined (thanks to adeneo who tested that), so changing 似乎IE返回的是undefined (感谢adeneo对其进行了测试),因此进行了更改

var color = $(colorIdFull).css('background');

to

var color = $(colorIdFull).css('background-color');

will do the trick 会成功的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM