123456789101112131415161718192021222324252627282930313233343536373839 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- .box{
- width: 100px;
- height: 100px;
- background-color: red;
- }
- .box2{
- border:3px solid black;
- }
- .box3{
- margin-top: 200px;
- }
- </style>
- </head>
- <body>
- <!-- <div class="box box2"></div> -->
- <div></div>
- <script>
- var oBox = document.getElementsByTagName("div")[0];
- // oBox.setAttribute("class","box");
- // 控制标签类名
- // oBox.className = "box";
- oBox.className = "box box2";
- // var str = "box2";
- // oBox.classList.remove("box2");
- // oBox.classList.add("box2");
- // oBox.classList.replace("box2","box3");
- </script>
- </body>
- </html>
|