gpt4 book ai didi

javascript - 使用javascript将颜色设置为字符串

转载 作者:太空宇宙 更新时间:2023-11-03 21:59:11 26 4
gpt4 key购买 nike

我正在构建一个动态数组并具有以下代码,我正在尝试为数组的“名称”添加颜色。除了 "fontcolor("red")" 之外,其他一切都完美无缺。

if (val < 0) {
myArray.push({
"name" : myVariable.fontcolor("red"),
"size" : -10
});
} else {
myArray.push({
"name" : myVariable,
"size" : 5
});
}

当显示在 HTML 页面上时,我最终得到以下内容:

<font color="red">Strong rubber(minus)</font> 

我实际上正在绘制图表,我正在使用 d3.js 绘制图表,我的代码绘制了“Dog Toys”。 myVariable 的值为“myVariable”

 <g style="cursor: pointer; opacity: 1; " transform="translate(0,0)"> 
<text x="-6" y="10" dy=".50em" text-anchor="end">Dog Toys</text>
<rect width="478.57142857142867" height="20" style="fill: #4682b4; "></rect>
</g>

当文本显示在网页上时,知道如何为文本设置颜色吗?

最佳答案

尝试

myVariable.style.color = "Red"

关于javascript - 使用javascript将颜色设置为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11722166/

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