gpt4 book ai didi

javascript - Javascript 中的十六进制颜色

转载 作者:行者123 更新时间:2023-11-28 20:13:56 26 4
gpt4 key购买 nike

在javaScript(在Photoshop中)中,当给十六进制颜色一个值时,它在引号中,例如“FCAA00”

 var hexCol = "FCAA00";
var fgColor = new SolidColor;
fgColor.rgb.hexValue = hexCol

但是当将变量传递给该值时,不需要引号。这是为什么?

 var hexCol = convertRgbToHex(252, 170, 0)
hexCol = "\"" + hexCol + "\""; // These quotes are not needed.
var fgColor = new SolidColor;
fgColor.rgb.hexValue = hexCol

这只是一个 JavaScript 怪癖还是我错过了幕后发生的事情。谢谢。

最佳答案

引号是一种语法结构,表示字符串文字。 IE。解析器知道引号之间的字符构成字符串的值。这也意味着它们不是值本身的一部分,它们仅与解析器相关。

示例:

// string literal with value foo
"foo"

// the string **value** is assigned to the variable bar,
// i.e. the variables references a string with value foo
var bar = "foo";

// Here we have three strings:
// Two string literals with the value " (a quotation mark)
// One variable with the value foo
// The three string values are concatenated together and result in "foo",
// which is a different value than foo
var baz = "\"" + bar + "\"";

最后一种情况是您尝试过的。它创建一个字面上包含引号的字符串。相当于写

"\"foo\""

这与“foo”明显不同。

关于javascript - Javascript 中的十六进制颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19475166/

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