function getRandomColor() {
// 生成0到255之间的随机整数
const r = Math.floor(Math.random() * 256);
const g = Math.floor(Math.random() * 256);
const b = Math.floor(Math.random() * 256);
// 将RGB值格式化为十六进制颜色代码
const color = `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase()}`;
return color;
}
// 示例使用
console.log(getRandomColor());