zoukankan      html  css  js  c++  java
  • Jquery实现点击菜单后显示对应的内容模块

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script src="jquery-2.1.4.min.js"></script>
        <style>
            *{
                margin: 0;
            }
            .cc{
                margin: 0 auto;
                width: 75%;
    
            }
            .menus{
                height: 50px;
                width: 1000px;
                background-color: royalblue;
                border: 1px solid blue;
            }
    
            .contents{
                height: 300px;
                width: 1000px;
                background-color: purple;
                border: solid goldenrod 1px;
            }
            .uu{
                line-height: 50px;
    
            }
            .uu li{
                display: inline-block;
    
            }
            .uu li{
                margin: -2.2px;
                padding-left: 6px;
                padding-right: 6px;
            }
    
            .getcolor{
                background-color: olivedrab;
                border-top: solid 2px red;
    
            }
    
            .hide{
                display: none;
            }
        </style>
    </head>
    <body>
        <div class="cc">
            <div class="menus">
                <ul class="uu">
                    <li class="getcolor" aa = "d1" onclick="f1(this)">菜单一</li>
                    <li aa = "d2" onclick="f1(this)">菜单二</li>
                    <li aa = "d3" onclick="f1(this)">菜单三</li>
                </ul>
            </div>
            <div class="contents">
                <div id="d1">内容一</div>
                <div id="d2" class="hide">内容二</div>
                <div id="d3" class="hide">内容三</div>
            </div>
        </div>
    </body>
            <script>
                function f1(self) {
                    $(self).addClass("getcolor").siblings().removeClass("getcolor");
                    //获取属性值
                    var getele = $(self).attr("aa");
                    // console.log(getele);
                    //改变内容
                    $("#"+getele).removeClass("hide").siblings().addClass("hide");
                }
            </script>
    </html>
  • 相关阅读:
    《程序猿闭门造车》之NBPM工作流引擎
    CryptographicException异常处理方法
    nodejs简单模仿web.net web api
    Windows Mobile设备操作演示准备工作小记
    PPT定时器小记
    winDBG排错小记
    Ubuntu 16.04应用布署小记
    Ubuntu 16.04环境布署小记
    Ubuntu 16.04系统布署小记
    Dokuwiki布署小记
  • 原文地址:https://www.cnblogs.com/TKOPython/p/12902670.html
Copyright © 2011-2022 走看看