JS——stye属性

1、样式少的时候使用

this.parentNode.style.backgroundColor="yellow";

2、style是对象

console.log(box.style);//返回object

3、值是字符串,没有设置值是“”;

console.log(box.style.border);//1px solid #ccc

4、命名规则,驼峰命名,和css不一样

this.parentNode.style.backgroundColor="yellow";//第二个单词首字母大写

5、设置了类样式不能获取,只和行内式交互,和内嵌和外链无关

<style>
//...里面的类样式通过js的style属性是获取不到的
</style>
<body>
     <div style=" 100px;"></div>//行内式js通过style属性可以获取
</body>

6、box.style.cssText = “字符串形式的样式”;

aRed.style.cssText=" 100px;height: 100px;background-color: #ccc;";//适合多个style属性值的设置
原文地址:https://www.cnblogs.com/wuqiuxue/p/7884134.html