gpt4 book ai didi

jquery - 在 jQuery 中将特定颜色替换为另一种颜色

转载 作者:行者123 更新时间:2023-12-01 08:07:31 26 4
gpt4 key购买 nike

我的网站上有以下颜色作为主题颜色:

#0088cc;

如何通过更改主体类在整个 DOM/网页中应用的每个元素上将此颜色替换为另一种颜色?

例如。

if ($('body').hassClass('black')){
replace all #0088cc with #000;
}

颜色代表所有不同的 html 颜色:边框、背景、文本颜色等

更新:

我发现大家都没有正确理解这个问题:

我的主题颜色是#0088cc。现在,体内的各种元素都具有这种颜色作为文本颜色、背景颜色、边框颜色。所以我想用新颜色替换主体子元素内的每种颜色(为某些元素定义了该颜色的所有元素),这样我就可以更改整个主题...

我该怎么做?

最佳答案

    var hexDigits = new Array
("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");

//Function to convert hex format to a rgb color
function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}

function hex(x) {
return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
}
$(document).ready(function(){
if ($('body').hassClass('black')){
$("*").each(function(){
if(rgb2hex($(this).css("color")) == "#0088cc")
$(this).css("color","black");
});}
});


Here the demo on jsFiddle http://jsfiddle.net/fAMAu/

关于jquery - 在 jQuery 中将特定颜色替换为另一种颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15613594/

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