js对节点进行操作

63 阅读1分钟
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width:200px;
            height:200px;
            border:1px solid #000;
        }
    </style>
</head>
<body>
    <div class="box" id="box"></div>
    <script>
        var oBox = document.getElementById('box');
        oBox.style.backgroundColor = 'rgb(100,200,123)';
        // oBox.style.backgroundColor = '#f80';
        oBox.style.width = '100px';
    </script>
</body>
</html>

==使用js对节点进行样式设置时通过打点调用style属性打点调用各属性时属性内部的-取消使用驼峰式的写法进行书写== ==在创作中标签选择器使用 class 和 id 选择器两种。通常使用类选择器通过css进行样式设置,使用id选择器通过js对样式进行设置==