• AngularJS--day05-评论案例


    <!DOCTYPE html>
    <html ng-app='app' ng-controller='mainController'>
        <head>
            <meta charset="utf-8">
            <title>评论案例</title>
            <link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
        </head>
        <body>
            <br /><br /><br />
            <div class="row">
                <div class="col-xs-3"></div>
                <div class="col-xs-6">
                    <!-- 评论模块 -->
                    <div class="input-group">
                        <input type="text" class="form-control" />
                        <span class="input-group-btn" ng-model='comt'>
                            <button class="btn btn-primary" ng-click='submitComment(comt)'>评论</button>
                        </span>
                    </div>
                    <!-- 评论标题 -->
                    <h2 ng-show='commentArr.length>0'>评论</h2><!-- 有显示 -->
                    <!-- 评论内容 -->
                    <ul class="list-group">
                        <li class="list-group-item" ng-repeat='comment in commentArr track by $index'>
                            <span>{{comment}}</span>
                            <a href="javascript:;" class="btn btn-link" ng-click='deleteComment($index)'>删除本条评论</a>
                        </li>
                    </ul>
                </div>
                <div class="col-xs-3"></div>
            </div>
            
            <script src="angular.js"></script>
            <script>
                var app = angular.module('app',[]);
                app.controller('mainController',['$scope',function($scope){
                    $scope.commentArr = [];
                    //评论功能
                    $scope.submitComment = function (comt){
                        $scope.commentArr.push(comt);
                        $scope.comt = '';
                    };
                    //删除评论
                    $scope.deleteComment = function(index){
                        $scope.commentArr.splice(index,1);//.splice(index,howmany,item1,.....,itemX)index    必需。整数,规定添加/删除项目的位置,使用负数可从数组结尾处规定位置。
                    };
                    
                }]);
            </script>
        </body>
    </html>
  • 相关阅读:
    函数
    字符串格式化
    集合
    习题02
    int/str/list/tuple/dict必会
    元组/字典
    列表方法
    练习题(format、expandtabs、片层)
    字符串方法
    JMM
  • 原文地址:https://www.cnblogs.com/fdxjava/p/11423890.html
Copyright © 2020-2023  润新知