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变量使用cssText更改div的高度_Javascript_Css - Fatal编程技术网

如何使用javascript变量使用cssText更改div的高度

如何使用javascript变量使用cssText更改div的高度,javascript,css,Javascript,Css,您需要字符串连接或。元素也应该是display:block 串联 var randomHeight=Math.floor((Math.random()*100)+50); document.getElementById(“child”).style.cssText=“显示:块;背景色:红色;高度:”+randomHeight+“px;宽度:100px;” ABC var randomHeight = Math.floor((Math.random()*100)+50); document.ge

您需要字符串连接或。元素也应该是
display:block

串联

var randomHeight=Math.floor((Math.random()*100)+50);
document.getElementById(“child”).style.cssText=“显示:块;背景色:红色;高度:”+randomHeight+“px;宽度:100px;”
ABC
var randomHeight = Math.floor((Math.random()*100)+50);
document.getElementById("child").style.cssText="background-color:red; height:randomHeight+'px'; width:100px;";