• AngularJs学习——实现列表内容项的增加删除


    效果截图:

    说明:引入bootstrap.min.css样式库和angular.min.js的静态资源库,实现列表内容的增加和删除操作。

    AngularJS代码

        <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
        <script>
            angular.module('myapp',[])
                   .controller('myctrl',function($scope){
                           $scope.item = '';
                           $scope.items = [];
                           //增加列表项方法
                           $scope.add = function(){
                               $scope.items.push($scope.item);
                           }
                   })
        </script>

    HTML代码

    <!DOCTYPE html>
    <html lang="en" ng-app="myapp">
    <head>
        <meta charset="UTF-8">
        <title>AngularJS实现列表内容项的增加、删除</title>
        <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css"/>
    </head>
    <body style="padding: 20px">
        <div class="container" ng-controller="myctrl">
            <div class="row">
                <div class="col-md-offset-2 col-md-5">
                <div class="input-group">
                    <input type="text" class="form-control" ng-model="item">
                    <span class="input-group-btn">
                        <button class="btn btn-primary" ng-click="add()">增加内容</button>
                    </span>
                </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-offset-2 col-md-5">
                    <h6 style="margin-top: 10px;" ng-if="items.length>0">列表内容:</h6>
                    <div class="list-group">
                        <div class="list-group-item" ng-repeat="item in items track by $index">
                            {{item}} <a href="#" ng-click="items.splice($index,1)">删除</a>
                        </div>
                    </div>                
                </div>
            </div>
        </div>
    </body>
    </html>
  • 相关阅读:
    解决Xcode 证书过期问题
    Parallel Desktop 问题汇总
    CMS系统学习笔记
    git pull报错 error: Your local changes to the following files would be overwritten by merge
    Mac安装Homebrew
    使用nvm-windows安装NodeJs遇到的问题: Could not retrieve https://nodejs.org/dist/latest/SHASUMS256.txt.
    HTB-靶机-Luke
    HTB-靶机-Fortune
    HTB-靶机-Ypuffy
    HTB-靶机-Sunday
  • 原文地址:https://www.cnblogs.com/lvmylife/p/5389111.html
Copyright © 2020-2023  润新知