学习JQUERY,写的选择页功能。

和其它的区别是用了.siblings()这个函数,不知道功能有什么影响。


HTML 代码:

<!DOCTYPE html>
<html>
    <head>
        <title>Menu Navigator</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs
/jquery/1.7.2/jquery.min.js"></script>
    </head>
    <body>
     <div class="tabbed-menu">
        <ul class="tabs">
        	<li id="tab_menu_1" class="selected">tab_menu_1</li>
        	<li id="tab_menu_2">tab_menu_2</li>
        	<li id="tab_menu_3">tab_menu_3</li>
            <li id="tab_menu_4">tab_menu_4</li>
        </ul>
        <div class="content">
        	<div class="page" >my text1</div>
        	<div class="page" style="display:none;">my text2</div>
        	<div class="page" style="display:none;">my text3</div>
            <div class="page" style="display:none;">my text4</div>
        </div>
     </div>
    </body>
</html>

CSS代码:

/*  This div class is the container for our menu.
                It defines attributes for everything inside. */
            div.tabbed-menu {
                font-family: "Helvetica";
                font-size: 15px;
                width: 600px;
            }

            /*  This ul class defines how your menu options
                will be arranged and also gives us a nice 
                dividing line between the menu and the content. */
            ul.tabs {
                text-align: center;
                list-style: none;
                position: relative;
                margin: 0;
                padding: 0;
                line-height: 26px;
                color: #0088CC;
                border-bottom: 1px solid #DDDDDD;
            }

            /*  This defines the look of the individual tabs of 
                your menu when they are contained in a tabs class ul */
            ul.tabs li {
                margin-bottom: -1px;
                padding: 3px 10px 0 10px;
                border: 1px solid #DDDDDD;
                background: #EFEFEF;
                
                /*  inline-block tells the browser to arrange the list
                    elements in a line rather than each element on its
                    own line. */
                display: inline-block;
                
                /* The attributes here round the top left
                    and right corners of the tabs. */
                border-top-left-radius: 6px; 
                border-top-right-radius: 6px;
            }
            /* This defines what a tab should look like when selected */
            ul.tabs li.selected {
                background: #FFF;
                border-bottom-color: transparent;
            }
            /* This defines how a tab looks when your mouse hovers above it */
            ul.tabs li:hover {
                color: #333333;
                cursor: pointer;
                background: #FFFFFF;
            }

            /*  This centers all of the text within a page element */
            div.page {
                text-align: center;
            }
            /*  This overrides the text centering we defined above if
                the text is within a list and also tells your browser
                not to put bullet points next to the text. */
            div.page li {
                text-align: left;
                list-style-type: none;
            }

JQUERY代码:

$(document).ready(function(){
                $('.tabs li').mouseover(function(){
                    if(!$(this).hasClass('selected')){
                        $(this).addClass('selected');
                        $(this).siblings().removeClass('selected');
                        var menuNum = parseInt($(this).attr('id').substr(9),10) - 1;
                        var $contentDiv = $(".content div:eq(" + menuNum + ")");
                        $contentDiv.css('display','block');
                        $contentDiv.siblings().css('display','none');
                    }
                });
            });


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

啵呗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值