HTML+CSS+JavaScript后台管理页面1: 实现头部菜单,内容中分为左侧菜单和右侧表格以及返回顶部,表格中实现全选,反选,取消,添加。

16 篇文章 0 订阅
11 篇文章 0 订阅

代码:

</html><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="font-awesome-4.7.0/css/font-awesome.min.css"/>
    <style>
        body{
            margin:0;
        }
        .hide{
            display:none;
        }
        .left{
            float:left;
        }
        .right{
            float:right;
        }
        .pg-header{
            height:50px;
            background-color:white;
            color:black;
            line-height:50px;
            padding:0 20px;

        }
        .pg-header .a{
            font-size:15px;
            padding:0 10px;
        }
        .pg-header .a .b{
            position:absolute;
            top:50px;
            right:20px;
            background-color:white;
            color:black;
            z-index:20;
            width:50px;
            display:none;
        }

        .pg-header .a:hover .b{
            display:block;
        }
        .pg-header .a .b a{
            display:block;
            height:35px;
        }
        .pg-header .c{
            margin-top:10px;
            height:30px;
            width:30px;
            line-height:30px;
            text-align:center;
            display:inline-block;
        }
        .pg-header .c:hover{
            background-color:gainsboro;
        }
        .pg-header .icons{
            padding:0 10px;
        }
        .pg-content{
            position:absolute;
            top:50px;
            bottom:0;
            left:0;
            right:0;
            background-color:gainsboro;
        }
        .pg-content .content-menu{
            height:510px;
            width:10%;
            margin:10px 70px;
            background-color:white;
        }
        .pg-content .content-menu a{
            display:block;
            height:25px;
            line-height:25px;
            text-align:center;
        }
        .pg-content .content-menu .d{
            font-size:15px;
            color:black;

        }
        .pg-content .content-menu .d:hover{
            background-color:red;
        }
        .pg-content .Content{
            position:absolute;    /*相对于pg-content的相对top,bottom,right,left*/
            top:10px;
            bottom:0;
            right:70px;
            left:250px;
            background-color:white;
            overflow:auto;
        }
        .pg-content .Content .e{
            text-align:center;
            margin-top:100px;
            font-size:18px;

        }
        .pg-content .Content .z1{
            position:fixed;
            left:0;
            top:0;
            right:0;
            bottom:0;
            background-color:gainsboro;
            opacity:0.6;
            z-index:9;
        }
        .pg-content .Content .z2{
            width:500px;
            height:400px;
            background-color:white;
            position:fixed;
            left:50%;
            top:50%;
            margin-left:-250px;
            margin-top:-200px;
            z-index:10;
        }



    </style>
</head>
<body>
    <div class="pg-header">
        <span class="left" style="font-size:25px; font-family:微软雅黑; color:darkred;">C</span>
        <span class="left" style="font-size:25px; font-family:微软雅黑; color:black;">SDN</span>
        <span class="left a" >首页</span>
        <span class="left a" >博客</span>
        <span class="left a" >学院</span>
        <span class="left a" >下载</span>
        <span class="left a" >GitChat</span>
        <span class="left a" >TinyMind</span>
        <span class="left a" >商城</span>
        <span class="left a" >VIP</span>
        <div class="left a " style="position:relative;">
            <span class="c">...</span>
            <div class="b">
                <a>论坛</a>
                <a>问答</a>
                <a>活动</a>
                <a>招聘</a>
                <a>IT eye</a>
                <a>CSTO</a>
            </div>
        </div>
        <span class="right">注册</span>
        <span class="right a">登录</span>
        <div class="icons right a">
            <i class="fa fa-commenting" aria-hidden="true" style="color:sandybrown;"></i>
            <span >chat</span>
        </div>
        <div class="icons right a">
            <i class="fa fa-pencil-square" aria-hidden="true" style="color:red;"></i>
            <span>写博客</span>
        </div>
    </div>
    <div class="pg-content">
        <div class="content-menu left">
            <a class="d">推荐</a>
            <a class="d">最新文章</a>
            <a class="d">关注</a>
            <a class="d">资讯</a>
            <a class="d">人工智能</a>
            <a class="d">云计算/大数据</a>
            <a class="d">区块链</a>
            <a class="d">数据库</a>
            <a class="d">程序人生</a>
            <a class="d">研发管理</a>
            <a class="d">前端</a>
            <a class="d">移动开发</a>
            <a class="d">物联网</a>
            <a class="d">运维</a>
            <a class="d">计算机基础</a>
            <a class="d">编程语言</a>
            <a class="d">架构</a>
            <a class="d">音视频开发</a>
            <a class="d">安全</a>
            <a class="d">其他</a>
        </div>
        <div class="Content right">
            <div class="e">

                <input type="button" value="添加" οnclick="AddModel();" />     <!--不会将添加,全选,取消,反选与表格的头对齐-->
                <input type="button" value="全选" οnclick="ChooseAll();" />
                <input type="button" value="取消" οnclick="CancleAll();" />
                <input type="button" value="反选" οnclick="ReverseAll();"/>
                <div style="height:20px;width:100px;"></div>
                <table border="1" align="center" bordercolor="blue" cellpadding="10" cellspacing="0" >
                    <thead>
                        <tr>
                            <th>选择</th>
                            <th>姓名</th>
                            <th>年龄</th>
                            <th>专业</th>
                            <th>爱好</th>
                        </tr>
                    </thead>
                    <tbody id="tb">
                        <tr>
                            <td>
                                <input type="checkbox" value="1" />
                            </td>
                            <td>小明</td>
                            <td>19</td>
                            <td>电子信息工程</td>
                            <td>游戏</td>
                        </tr>
                        <tr>
                            <td>
                                <input type="checkbox" value="2" />
                            </td>
                            <td>小花</td>
                            <td>19</td>
                            <td>计算机</td>
                            <td>编程</td>
                        </tr>
                        <tr>
                            <td>
                                <input type="checkbox" value="3" />
                            </td>
                            <td>小龙</td>
                            <td>24</td>
                            <td>软件工程</td>
                            <td>软件设计</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div id="i1" class="z1 hide"></div>
            <div id="i2" class="z2 hide">
                <p>
                    <label for="username" >姓名:</label>
                    <input id="username" type="text" name="user" />
                </p>
                <p>
                    <label for="age0" >年龄:</label>
                    <input  id="age0" type="text" name="age" />
                </p>
                <p>
                    <label for="major0">专业:</label>
                    <input  id="major0"  type="text" name="major"/>
                </p>
                <p>
                    <label for="hobby0">爱好:</label>
                    <input  id="hobby0"  type="text" name="hobby"/>
                </p>
                <p>
                    <input type="button" value="取消" οnclick="HideModel()"/>
                    <input type="button" value="确定" />
                </p>
            </div>
            <div style="position:absolute;bottom:0;right:0;width:60px;height:30px;font-size:15px;">返回顶部</div>

        </div>
    </div>

    <script>
        function AddModel(){
            document.getElementById("i1").classList.remove('hide');
            document.getElementById("i2").classList.remove('hide');
        }
        function HideModel(){
            document.getElementById("i1").classList.add('hide');
            document.getElementById("i2").classList.add('hide');
        }
        function ChooseAll(){
            var tbody = document.getElementById("tb");
            var tr_list = tbody.children;
                for (var i = 0; i < tr_list.length; i++) {
                  var current_tr = tr_list[i];
                  var checkbox = current_tr.children[0].children[0];
                  checkbox.checked = true;
                }

        }
        function CancleAll(){
            var tbody=document.getElementById("tb");
            var tr_list=tbody.children;
                for(var i=0;i<tr_list.length;i++){
                      var current_tr=tr_list[i];
                      var checkbox=current_tr.children[0].children[0];
                      checkbox.checked=false;
                  }
        }


        function ReverseAll(){
            var tbody=document.getElementById("tb");
                  var tr_list=tbody.children;
                  for(var i=0;i<tr_list.length;i++){
                      var current_tr=tr_list[i];
                      var checkbox=current_tr.children[0].children[0];
                      if(checkbox.checked){
                          checkbox.checked=false;
                      }else{
                          checkbox.checked=true;
                      }
                  }

        }
    </script>

</body>
</html>

效果:


点添加后页面:


  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供一个基本的HTML+CSS+jQuery示例实现,如下所示: ```html <!DOCTYPE html> <html> <head> <title>复选框操作示例</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style type="text/css"> .container { margin: 20px; } .checkbox-group { margin-bottom: 10px; } .checkbox-group label { margin-right: 10px; } .button-group { margin-top: 10px; } </style> </head> <body> <div class="container"> <div class="checkbox-group"> <label><input type="checkbox" name="checkbox[]" value="1">选项1</label> <label><input type="checkbox" name="checkbox[]" value="2">选项2</label> <label><input type="checkbox" name="checkbox[]" value="3">选项3</label> <label><input type="checkbox" name="checkbox[]" value="4">选项4</label> <label><input type="checkbox" name="checkbox[]" value="5">选项5</label> </div> <div class="button-group"> <button id="select-all">全选</button> <button id="select-inverse">反选</button> <button id="select-none">全不选</button> </div> </div> <script type="text/javascript"> $(function() { // 全选 $('#select-all').click(function() { $('input[type="checkbox"]').prop('checked', true); }); // 反选 $('#select-inverse').click(function() { $('input[type="checkbox"]').each(function() { $(this).prop('checked', !$(this).prop('checked')); }); }); // 全不选 $('#select-none').click(function() { $('input[type="checkbox"]').prop('checked', false); }); }); </script> </body> </html> ``` 在这个示例,我们首先定义了一个包含5个复选框的`checkbox-group`,并且定义了一个包含三个按钮的`button-group`。然后,我们使用jQuery来实现三个操作: 1. 全选:当用户点击`select-all`按钮时,我们使用`prop`方法将所有复选框的`checked`属性设置为`true`,从而实现全选的功能。 2. 反选:当用户点击`select-inverse`按钮时,我们使用`each`方法遍历所有复选框,并对每个复选框的`checked`属性取反,从而实现反选的功能。 3. 全不选:当用户点击`select-none`按钮时,我们使用`prop`方法将所有复选框的`checked`属性设置为`false`,从而实现全不选的功能。 希望这个示例能够帮助您实现您的需求!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值