@案例可以将下边代码拷贝到bootstrap模板html中测试):
<style type="text/css">
    ol, ul {
        list-style: outside none none;
    }
    .tab{
        border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    }
    .tab .current{
        overflow:hidden;
        background-color: rgba(255, 255, 255, 0.4);
    }    
    .tab ul {
        height: 36px;
        margin: 0 auto;
        padding: 0 30px;
        width: 70%;
    }
    .tab li {
        background-color: rgba(0, 0, 0, 0.1);
        border-radius: 2px 2px 0 0;
        font-size: 14px;
        height: 36px;
        line-height: 36px;
        margin-right: 5px;
        text-align: center;
        width: 130px;
        float: left;
    }    
    .tab li a{
        display:block;
        height:36px;
        width:130px;
        color:white;
        outline:none;
        text-decoration: none;
    }
</style>
<div class="tab">
    <ul>            
        <li class="current"><a href="#">返回主页</a></li>
        <li><a href="#">查看天气</a></li>
    </ul>
</div>
<script type="text/javascript">
    $(".tab a").click(function(e){
        //这里e就是event事件,在这里即click事件,event.target为触发该事件的DOM元素。W3school中JQuery 事件中有介绍   http://www.w3school.com.cn/jquery/jquery_ref_events.asp
        $(e.target).parent().addClass("current").siblings(".current").removeClass("current");
        //parent()方法返回被选元素的直接父元素,siblings()方法返回被选元素的所有同胞元素。W3school中JQuery遍历中有介绍  http://www.w3school.com.cn/jquery/jquery_traversing_ancestors.asp
        $(e.target).removeClass("current");
        //removeClass() - 从被选元素删除一个或多个类。W3school中JQuery CSS类中有介绍  http://www.w3school.com.cn/jquery/jquery_css_classes.asp
    });
</script>

 

@12个用得着的JQuery代码片段网页截图:

posted on 2015-11-08 21:09  学到老死  阅读(398)  评论(0)    收藏  举报