Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 背景色不是背景色_Javascript_Css - Fatal编程技术网

Javascript 背景色不是背景色

Javascript 背景色不是背景色,javascript,css,Javascript,Css,当我在CSS中使用Javascript更改样式时,为什么使用背景色不起作用 这项工作: document.getElementById("circ").style.backgroundColor = getRandomColor(); 但这不起作用: document.getElementById("circ").style.background-color = getRandomColor(); -是。它不能出现在标识符中,该标识符是点表示法属性 您也可以使用背景色属性名称,只需使用允许-

当我在
CSS
中使用Javascript更改样式时,为什么使用
背景色
不起作用

这项工作:

document.getElementById("circ").style.backgroundColor = getRandomColor();
但这不起作用:

document.getElementById("circ").style.background-color = getRandomColor();
-
是。它不能出现在标识符中,该标识符是点表示法属性

您也可以使用
背景色
属性名称,只需使用允许
-
字符的符号即可


document.body.style[“背景色”]=“蓝色”在JavaScript中,
-
是一个减法运算符,因此使用该代码,您要它执行以下操作:

在名为“style”的对象上使用名为“background”的变量

从中减去名为“color”的变量的值

将其设置为等于getRandomColor()的结果


这真的没什么意义。这就是为什么JavaScript在camelCase中引用带有破折号的css样式。

backgroundColor是属性名。就这样