cssText的使用(原生js添加css样式)

参考:
https://www.cnblogs.com/majingyi/p/6840818.html
https://www.cnblogs.com/sky903700252/p/7382808.html

var head= document.getElementById("head");
head.style.width = "200px";
head.style.height = "70px";
head.style.display = "block";

将多行简化成一行,减少渲染:

var head= document.getElementById("head");
head.style.cssText="width:200px;height:70px;display:bolck";

但cssText也有个缺点,会覆盖之前的样式。
可以在前面添加一个分号来解决这个问题:

Element.style.cssText += ';width:100px;height:100px;top:100px;left:100px;'

版权声明:本文为weixin_42995876原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。