Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.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_Styling - Fatal编程技术网

Javascript 为什么所需的属性没有添加到变量中?

Javascript 为什么所需的属性没有添加到变量中?,javascript,css,styling,Javascript,Css,Styling,我不明白为什么属性没有设置为变量 为什么颜色不变? 代码如下: var text=document.createElement('h2'); text.textContent='text'; setAttribute(“样式”,“颜色:红色,边距顶部:5px”); document.body.appendChild(文本)更改颜色:红色,页边顶部:5px为颜色:红色;页边距顶部:5px var text=document.createElement('h2'); text.textConten

我不明白为什么属性没有设置为变量 为什么颜色不变?

代码如下:
var text=document.createElement('h2');
text.textContent='text';
setAttribute(“样式”,“颜色:红色,边距顶部:5px”);

document.body.appendChild(文本)更改
颜色:红色,页边顶部:5px
颜色:红色;页边距顶部:5px

var text=document.createElement('h2');
text.textContent='text';
setAttribute(“样式”,“颜色:红色;页边空白顶部:5px”);
document.body.appendChild(文本)