zoukankan      html  css  js  c++  java
  • 小练习之通过class属性增删修改属性

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            *{
                margin: 0;
            }
            #div1{
                height: 550px;
                width: 100%;
                background: royalblue;
                position: fixed;
                z-index: 1;
    
            }
            #div2{
                margin-left: 550px;
                margin-top: 150px;
                height: 200px;
                width: 300px;
                background: yellowgreen;
                position: fixed;
                z-index: 2;
                text-align: center;
                padding-top: 120px;
            }
            .cc{
                display: none;
            }
        </style>
    </head>
    <body>
        <div id="div1"><p onclick="f1()">显示</p></div>
    
        <div id="div2" class="cc cctv"><p onclick="f2()">隐藏</p></div>
                        //涉及到class等多个地方使用是,要多加几个名字
    </body>
    <script>
        function f1() {
            var ele = document.getElementsByClassName("cctv")[0];
    
            ele.classList.remove("cc");   //给标签添加删除属性
    
        }
        function f2() {
            var ele = document.getElementsByClassName("cctv")[0];
            ele.classList.add("cc");
    
        }
    </script>
    </html>
  • 相关阅读:
    学生信息管理系统
    设计模式,单例模式
    基础考试题(1)
    基础考试题(0)
    python面向对象进阶
    python面向对象
    Python反射
    14 定时器
    13 JS中的面向对象
    12 DOM操作的相关案例
  • 原文地址:https://www.cnblogs.com/TKOPython/p/12831144.html
Copyright © 2011-2022 走看看