angularJS实现表格部分列展开缩起

在这里插入图片描述
在这里插入图片描述

<html>
<head>
    <title> New Document </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>

    <!--    <script src='https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js'></script>-->
    <style type="text/css">
        table, tr, td, caption{
            border:1px solid #666;
            border-collapse:collapse;
            background-color:rgb(210, 219, 236);
        }

        td, caption{
            /*font-family:'微软雅黑';*/
            font-family: "Fira Code Light";
            font-size:12px;
            text-align:center;
            padding:3px 15px;
        }

        caption{
            border-bottom:none;
            cursor:pointer;
        }
    </style>

    <script>
        var app = angular.module('myApp', []);
        app.controller('myCtrl', function($scope) {
            //默认缩起
            $scope.myVar = true
            //显示隐藏按钮
            $scope.openClose = function () {
                $scope.myVar = !$scope.myVar;
                $scope.myVar1 = !$scope.myVar1;
            };
        });

    </script>
</head>

<body>
<table ng-app="myApp" ng-controller="myCtrl">
    <caption ng-click="openClose()">显示/隐藏价格</caption>
    <tr>
        <td >产品</td>
        <td ng-hide = 'myVar1' ng-click="openClose()">...</td>
        <td  ng-hide = 'myVar'>价格</td>
        <td  ng-hide = 'myVar'>价格</td>
        <td  ng-hide = 'myVar'>价格</td>
        <td  ng-hide = 'myVar'>价格</td>
        <td >销量</td>
    </tr>
    <tr>
        <td>A</td>
        <td ng-hide = 'myVar1'>...</td>
        <td  ng-hide = 'myVar'>18元</td>
        <td  ng-hide = 'myVar'>28元</td>
        <td  ng-hide = 'myVar'>38元</td>
        <td  ng-hide = 'myVar'>48元</td>
        <td>2</td>
    </tr>
    <tr>
        <td>B</td>
        <td ng-hide = 'myVar1'>...</td>
        <td  ng-hide = 'myVar'>77元</td>
        <td  ng-hide = 'myVar'>88元</td>
        <td  ng-hide = 'myVar'>88元</td>
        <td  ng-hide = 'myVar'>88元</td>
        <td>3</td>
    </tr>
    <tr>
        <td>C</td>
        <td ng-hide = 'myVar1'>...</td>
        <td  ng-hide = 'myVar'>66元</td>
        <td  ng-hide = 'myVar'>88元</td>
        <td  ng-hide = 'myVar'>88元</td>
        <td  ng-hide = 'myVar'>88元</td>
        <td>4</td>
    </tr>
</table>
</body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值