image.png
    点击之后
    image.png

    1. <p id="test">hello world</p>
    2. <script>
    3. /*
    4. style
    5. 属性
    6. cssText -->批量操作css
    7. length (了解)
    8. getPropertyValue()
    9. item() -->返回对应位置的css属性名
    10. removeProperty()
    11. setProperty
    12. */
    13. var test = document.getElementById("test");
    14. test.style.cssText = "color:red;background-color:#333;font-size:14px;";
    15. console.log(test.style.getPropertyValue("color"))
    16. console.log(test.style)
    17. console.log(test.style.item(0))
    18. test.onclick = function(){
    19. this.style.removeProperty("color")
    20. this.style.setProperty("background-color","green")
    21. }
    22. </script>