Js DOM 修改 css Style

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            #p1
            {
                border: 1px solid;
            }
        </style>
    </head>
    <body>
        <p style="color: royalblue" id="p1">Today is 2018.02.01</p>
        <script>
            window.onload = function()
            {
                console.log(document.getElementById("p1").style.color);
                console.log(document.getElementById("p1").style.border);
                document.getElementById("p1").style.color =  "black";
                
            }
        </script>
    </body>
</html>

控制台打印

[Web浏览器] "rgb(65, 105, 225)"    /htmlAndjs/domCss.html (18)
[Web浏览器] ""    /htmlAndjs/domCss.html (19)

  document.getElement("p1").style 只能获取到内联样式

原文地址:https://www.cnblogs.com/alway-july/p/8399498.html