更新时间:2023-12-02 23:40:28
问题是,即使您声明为十六进制,jquery也会返回rgb(...),所以我只添加了函数将十六进制转换为rgb:
The problem is that jquery returns rgb(...) even if you declare as HEX so i just added a function to translate hex to rgb:
function hex2rgb(hex) {
return ['0x' + hex[1] + hex[2] | 0, '0x' + hex[3] + hex[4] | 0, '0x' + hex[5] + hex[6] | 0];
}
不仅仅是修改您的代码:
and than just adapted your code:
$(document).ready(function (e) {
// Color to change
var targetHex = hex2rgb('#eb2c33');
$('body *').each(function(index) {
var rgbg = $(this).css('background-color');
if(rgbg == 'rgb('+targetHex[0]+', '+targetHex[1]+', '+targetHex[2]+')'){
$(this).addClass('jcbg');
}
});
});
这是小提琴