zoukankan      html  css  js  c++  java
  • tab 栏切换

    <!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>
            span {
                display: inline-block;
                 80px;
                height: 30px;
                background-color: #ccc;
                line-height: 30px;
                text-align: center;
                cursor: pointer;
                margin-bottom: 20px;
            }
            
            #box div {
                display: none;
                 300px;
                height: 100px;
                line-height: 100px;
                text-align: center;
                font-size: 30px;
                border: 1px solid #ccc;
            }
            
            span.bg {
                background-color: red;
                color: white;
            }
        </style>
    </head>

    <body>
        <div id="box">
            <!-- /*初始化样式 bg*/ -->
            <span class="bg">html</span>
            <span>css</span>
            <span>
                JS
            </span>
            <div style="display: block;">HTML</div>
            <div>CSS</div>
            <div>JS</div>
        </div>
        <script>
            var spans = document.querySelectorAll('span');
            var divs = document.querySelectorAll('#box div');
            for (var i = 0; i < spans.length; i++) {
                spans[i].index = i;
                //点击之后的排他思想
                spans[i].onclick = function() {
                    for (var i = 0; i < spans.length; i++) {
                        spans[i].className = '';
                        divs[i].style.display = 'none';
                    }
                    this.className = 'bg';
                    divs[this.index].style.display = 'block';
                }
            }
        </script>
    </body>

    </html>
  • 相关阅读:
    Spring优雅关闭之:ShutDownHook
    RocketMQ一直打印RocketmqRemoting closeChannel: close the connection to remote address[] result: true
    MVC中使用内建的HTML辅助方法产生表单元素提交表单与button按钮事件的陷阱
    js代码生成form,解决mvc的url参数过长问题
    jQuery中关于height,innerWidth与outerWidth的区别
    Chrome和Firefox浏览器执行new Date() 函数传参数得到不同结果的陷阱
    SQL时间段查询、分页、in字符串正则拆分
    JAVA初始化文件代码
    Base64加密URL、解密URL
    Spring XML model validation
  • 原文地址:https://www.cnblogs.com/ximenchuifa/p/13403086.html
Copyright © 2011-2022 走看看