HTML中的DIV切换

需求为一个页面的部分模块,随按钮点击进行切换。如图为tab1和tab2,点击“进行中”和“已结束”实现切换。

在这里插入图片描述
在这里插入图片描述

1. 添加两个按钮

<div style="font-size: 0"><!--取出两个button之间的间隙-->
                <button style="outline:none;border-radius:5px;background-color: #fdfdfe;border: none;width: 75px;height: 28px"
                        onclick="showDiv();">
                    <font size="4" color="#4a90e2">进行中</font></button>
                <button style="outline:none;border-radius:5px;background-color: #fdfdfe;border: none;width: 75px;height: 28px"
                        onclick="showDiv();">
                    <font size="4" color="#4a90e2">已结束</font></button>
  </div>

2. 添加两个div(要展现得内容在这里编写)

            <div id="div1" class="col-md-7 agileits_mail_grid_left"
                 style="display: block;background-color: #ffffff;border-radius:10px">
                <table class="table" style="background-color: #ffffff">
                    <tbody>
                    <tr>
                        <th class="anchorjs-icon"><font size="4" color="black">赛事名称</font></th>
                        <th class="anchorjs-icon"><font size="4" color="black">时间</font></th>
                        <th class="anchorjs-icon"><font size="4" color="black">主办方</font></th>
                    </tr>
                   <tr>
                   <!--从数据库中取对应的数据-->
                   </tr>
                    </tbody>
                </table>
            </div>

            <div id="div2" class="col-md-7 agileits_mail_grid_left"
                 style="display: none;background-color: #ffffff;border-radius:10px">
                <table class="table" style="background-color: #ffffff">
                    <tbody>
                    <tr>
                        <th class="anchorjs-icon"><font size="4" color="black">赛事名称</font></th>
                        <th class="anchorjs-icon"><font size="4" color="black">时间</font></th>
                        <th class="anchorjs-icon"><font size="4" color="black">主办方</font></th>
                    </tr>
                     <tr>
                   <!--从数据库中取对应的数据-->
                   </tr>
                    </tbody>
                </table>
            </div>

3. 添加JS函数(判断点击的是哪一个按钮)

        <script>
            function showDiv() {
                var div1=document.getElementById("div1");
                var div2=document.getElementById("div2");
                if (div1.style.display=='block')
                    div1.style.display='none';
                else div1.style.display='block';
                if (div2.style.display=='block')
                    div2.style.display='none';
                else div2.style.display='block';
            }
        </script>

以上可以写在一个文件里。

  • 5
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值