1、element.style.csstyle='属性值’
注意:
a、css属性的-去掉,换成首字母大写,例如text-align变成textAlign
b、当属性是js的保留字时,在属性前面加css,例如cssFloat
2、element.style.cssText='css样式’
<style>#box{width: 200px;height: 200px;background-color: red;}</style><div id="box" class="box" title="ahahah">盒子</div><script>var box=document.getElementByClassName('box');/*方法一*/box.style.width='200px';box.style.backgroundColor='black';/*方法二*/box.style.cssText='width:200px;background-color:black;';</script>