1. cssText -->批量操作css
  2. length(了解)
  3. getPropertyValue() 获取style属性里面的值
  4. item() 返回对应位置的css属性名
  5. removeProperty() 移除属性
  6. setProperty() 设置属性

1.cssText—批量操作css

  1. 语法:
  2. element.style.cssText=attr
  1. <div id="test">hello world</div>
  2. <script>
  3. var test = document.getElementById("test");
  4. test.onclick = function(){
  5. this.style.cssText="border:1px solid #333;color:red";
  6. }
  7. </script>

2.length

  1. <div id="test" style="color:red;font-size: 18px">hello world</div>
  2. <script>
  3. var test = document.getElementById("test");
  4. test.onclick = function(){
  5. alert(this.style.length)
  6. }
  7. </script>

3.getPropertyValue()—获取style属性里面的值

  1. <div id="test" style="color:red;font-size: 18px">hello world</div>
  2. <script>
  3. var test = document.getElementById("test");
  4. test.onclick = function(){
  5. alert(this.style.getPropertyValue("color"))
  6. console.log(this.style.color)
  7. }
  8. </script>

4.item()—返回对应位置的css属性名

  1. <div id="test" style="color:red;font-size: 18px">hello world</div>
  2. <script>
  3. var test = document.getElementById("test");
  4. test.onclick = function(){
  5. alert(this.style.item(0)) //color
  6. }
  7. </script>

5.removeProperty()—移除属性

  1. <div id="test" style="color:red;font-size: 18px">hello world</div>
  2. <script>
  3. var test = document.getElementById("test");
  4. test.onclick = function(){
  5. this.style.removeProperty("color")
  6. }
  7. </script>

6.setProperty()—设置属性

  1. 语法:
  2. setProperty(attr,value)
  3. //this.style.setProperty("background-color","red")
  1. <p id="test">hello world</p>
  2. <script>
  3. var test=document.getElementById("test");
  4. test.style.cssText="color:red;background-color:#333;font-size:14px"
  5. console.log(test.style.getPropertyValue("color"))
  6. console.log(test.style)
  7. console.log(test.style.item(0))
  8. test.onclick=function(){
  9. this.style.removeProperty("color")
  10. this.style.setProperty("background-color","green")
  11. }
  12. </script>