gpt4 book ai didi

jquery - .css 不工作给出空值

转载 作者:太空宇宙 更新时间:2023-11-03 18:55:51 25 4
gpt4 key购买 nike

我有一个索引,它根据用户的选择更改其模板。一旦用户更改其模板,我希望菜单也改变颜色。它适用于所有浏览器,但在 IE 中它给我错误 '1' is null or not an object in the line return "#"+ hex(bg[1]) + hex(bg[2]) + hex (bg[3]);

这是我的代码

jQuery(document).ready(function(){

var bg = convert(jQuery('#body').css('background-color'));
var font = convert(jQuery('.left').css('color'));
if(bg =='#ffffff' || bg=='undefined'){
bg = '#000000';
font='#ffffff';
}


jQuery('.mainmenu').hover(
function(){
var $this = $(this);
$this.data('bgcolor', $this.css('background-color')).css('background-color', '#FFFFFF' );
},
function(){
var $this = $(this);
$this.css('background-color', $this.data('bgcolor'));
}
);
jQuery('.submenu').hover(
function(){
var $this = $(this);
$this.data('bgcolor2', $this.css('background-color')).css('background-color', bg );
},
function(){
var $this = $(this);
$this.css('background-color', $this.data('bgcolor2'));
}
);
jQuery('.submenu2').hover(
function(){
var $this = $(this);
$this.data('color', $this.css('color')).css('color', font );
},
function(){
var $this = $(this);
$this.css('color', $this.data('color'));
}
);
});
function convert(bg){
bg = bg.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return "#" + hex(bg[1]) + hex(bg[2]) + hex(bg[3]);
}
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
</scri

最佳答案

答案来自:Javascript match doesn't work in IE IE 将 rgb 值转换为十六进制,因此 .match 传递了一个不同的值。

关于jquery - .css 不工作给出空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13504834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com