改变节点css和属性

 
<!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>改变节点css和属性</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 = 'red'

        obox.setAttribute('data-n',10)

        var n = obox.getAttribute('data-n')
        console.log(n);

    </script>
</body>
</html>
posted @ 2021-12-06 20:58  13522679763-任国强  阅读(32)  评论(0)    收藏  举报