zoukankan      html  css  js  c++  java
  • Jquery 实现标签切换效果

    1、效果图

    2、HTML代码如下

    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <script src="IndusJS/jquery.min.js"></script>
        <style type="text/css">
    .main02 {width:100%;}
    #title02 {height:25px;line-height:25px;overflow:hidden;border-bottom:2px solid black;}
    #title02 ul
    {
      width:100%;
      height:25px;
      margin:0px;
    
    }
    #title02 ul li {float:left; width:65px; height:20px;line-height:20px; color:#333;list-style:none;  cursor:pointer; font-weight:bold;text-align:center;}
    #title02 li.on {background-color:blueviolet;color:white;}
    #con02 {background:#fafafa;height:100px;}
    #con02 div.off {display:none; padding:5px;}
    #con02 div.on {display:block;}
        </style>
    </head>
    <body>
    <div style="400px;height:500px;">
        <div id="diva0" class="main02">
          <div id="title02">
            <ul>  
               <li class="on">标题1</li>
               <li>标题2</li>
               <li>标题3</li>
            </ul>
          </div>
          <div id="con02" style="100%;height:70px;">
           <div id="diva2" class="on" style="padding:15px 0px 0px 15px;">
          标题1
         </div>
           <div id="diva3" class="off">
             标题2
         </div>
           <div id="diva4" class="off">
         标题3
        </div>  
          </div>
        </div>
    </div>
       
    </body>
    </html>
    <script type="text/javascript">
        var bTitle = document.getElementById('title02');
        var cSpan = bTitle.getElementsByTagName('li');
    
        var i = 0;
        for (i = 0; i < cSpan.length; i++) {
            switch (i) {
                case 0:
                    cSpan[0].onclick = function () {
                        cSpan[0].className = 'on';
                        cSpan[1].className = '';
                        cSpan[2].className = '';
                        $('#diva2').attr('class', 'on');
                        $('#diva3').attr('class', 'off');
                        $('#diva4').attr('class', 'off');
                   
                    }
                    break;
                case 1:
                    cSpan[1].onclick = function () {
                        cSpan[0].className = '';
                        cSpan[1].className = 'on';
                        cSpan[2].className = '';
    
                        $('#diva2').attr('class', 'off');
                        $('#diva3').attr('class', 'on');
                        $('#diva4').attr('class', 'off');
                     
                    }
                    break;
                case 2:
                    cSpan[2].onclick = function () {
                        cSpan[0].className = '';
                        cSpan[1].className = '';
                        cSpan[2].className = 'on';
    
                        $('#diva2').attr('class', 'off');
                        $('#diva3').attr('class', 'off');
                        $('#diva4').attr('class', 'on');
                   
                    }
                    break;
    
    
    
            }
        }
    </script>
  • 相关阅读:
    OCP 062【中文】考试题库(cuug内部资料)第29题
    413. 等差数列划分 力扣(中等) 找规律,细节
    264. 丑数 II 力扣(中等) 动态规划,不会
    313. 超级丑数 力扣(中等) 动态规划,不会做
    5840. 使字符串平衡的最小交换次数 力扣(中等) 第255场oppo周赛 猜出来的
    手写一个仿微信登录的Nodejs程序
    你不知道的CSS国际化
    React实现类似淘宝tab居中切换效果
    原来 CSS 这样写是会让 App 崩溃的
    css中class和id之间有什么区别?
  • 原文地址:https://www.cnblogs.com/net064/p/10239064.html
Copyright © 2011-2022 走看看