使用AngularJS制作一个选项卡

HTML:

<!DOCTYPE html>
<html ng-app="tabApp">
    <head>
        <meta charset="UTF-8">
        <title>tabs02</title>
        <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
        <link rel="stylesheet" href="../css/tabs01.css" />
    </head>

    <body>
        <div class="container" ng-controller="tabCtrl">
            <ul ng-init='tab=0'>
                <li ng-class='{active:tab==$index}' ng-click="show($index)" ng-repeat="x in arrays">{{x.title}}</li>
            </ul>
            <div class="Tabdiv">
                <div ng-show="tab==$index" ng-repeat="x in arrays">{{x.word}}</div>
            </div>
        </div>
    </body>
</html> 

JS:

<script>
        var app = angular.module("tabApp",[]);
        app.controller('tabCtrl',function($scope){
            $scope.arrays = [
            {"title":"湖人",
             "word":"科比,奥尼尔、贾巴尔"
            },{
                "title":"热火",
                "word":"韦德,波什"
            },{
                "title":"骑士",
                "word":"詹姆斯,欧文"
            },{
                "title":"马刺",
                "word":"邓肯、帕克、吉诺比利"
            }];
            $scope.show = function(index){
                $scope.tab = index;
            };
        });
    </script>

CSS:

* {
    list-style: none;
    margin: 0;
    padding: 0;
}
.container{
    width: 500px;
    height: 300px;
}
.Tabdiv{
    width: 405px;
    height: 200px;
    background: #eee;
    border: 1px solid black;
    border-top: none;
}
ul li{
    width: 100px;
    height: 30px;
    text-align: center;
    display: block;
    float: left;
    background: #CCCCCC;
    border: 1px solid #EDEDED;
    cursor: pointer;
    padding: 5px 0;
}
ul li.active{
    background: #eee;
    border-bottom: none;
}

图片:

这里写图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值