zoukankan      html  css  js  c++  java
  • angualr 实现tab选项卡功能

    tab.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>test</title>
    </head>
    <body ng-app="myApp">
     <div ng-controller="myCtr">
        <div my-title data="data"></div>
     </div>  
     
    <script src="angular.min.js"></script>
    <script src="jquery-3.1.1.min.js"></script>
    <script>
    var app = angular.module("myApp", [])
    app.controller('myCtr', ["$scope",function($scope){
        $scope.data = [
            {title:"英雄联盟",data:[
                  {title:"诺克"},
                  {title:"剑圣"}
            ]},
            {title:"王者荣耀",data:[
                   {title:"刘备"},
                   {title:"兰陵王"}
            ]}
           ];
    }]);
    app.directive('myTitle', function(){
       return {
       	restrict: 'EA',
       	templateUrl: 'time.html',
       	scope: {data:'=data'},
       	link: function(scope, elem, attr){                //link用来操作DOM元素
             $(elem).delegate('a', 'click', function(){       //外部文件的元素绑定事件要用liveondelegate,根据jquery版本来选
                $('a').removeClass('active');                 //移除a标签class
                $(this).addClass('active');                   //为当前元素添加类
                var index = $(this).index();                  //获取序号index
                $(elem).find("div.list").hide();
                $(elem).find("div.list").eq(index-1).show();  //eq()方法获取索引,所以index需 -1
             });
       	}
       }
    });
    </script>
    </body>
    </html>
    

    time.html

    • 父元素ng-repeath后,子元素ng-repeat才有效
    
    <div class="tab">
        <style>
        	.tab a { text-decoration: none; display: inline-block;  border: 1px solid #ccc;}
        	.tab div {border: 1px solid #ccc; 200px; height:200px; margin: 0;}
        	.active {background-color: #aaa; color: #fff;}
        </style>
    	<a ng-repeat="v in data" href="#" ng-class="{active:$first}">{{v.title}}</a>
    	<div ng-repeat="v in data" ng-style="{display: $first?'block':'none'}" class="list">  <!-- 父元素ng-repeat -->
    		<ul>
    			<li ng-repeat="m in v.data">{{m.title}}</li>                          <!-- 子元素ng-repeat -->
    		</ul>
    	</div>
    </div>
    
    异乡小龟
  • 相关阅读:
    把arguments转化成数组
    最小化重绘和重排
    选择器API
    事件委托
    WAhaha_hnu (zoj 2010 oct月赛)
    素数计数公式全面拉丁化改写小有改进Meissel公式梅塞尔Lehmer公式莱梅=勒梅尔筛法三种形式孟庆余公式(转载)
    NBUT 2013 Timed NOJ Training #005
    2013 腾讯马拉松初赛第一场
    hrboj 1683 树形DP
    哈尔滨2013校赛训练赛 4 解题思路
  • 原文地址:https://www.cnblogs.com/scale/p/6238536.html
Copyright © 2011-2022 走看看