以十六进制设置背景颜色 [英] Set background color in hex

查看:475
本文介绍了以十六进制设置背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JavaScript中将元素背景颜色设置为十六进制值? backgroundColor 方法仅在rgb中设置。

How to set elements background color as hex value in JavaScript? backgroundColor method sets only in rgb.

square.style.backgroundColor = input_color;
input_color 是#123456,但在源集 rgb(18,52,86)

square.style.backgroundColor = input_color; input_color is #123456, but in the source sets rgb(18, 52, 86)

推荐答案

更好的解决方案就是设置背景颜色

A better solution to your problem would be just to set the background color like this

square.style.backgroundColor = "rgb(12,34,56)";

否则我会使用Sheika的例子

Otherwise I would use Sheika's example

这篇关于以十六进制设置背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆