下面我就為大家分享一篇angularJS實作動態添加,刪除p方法,具有很好的參考價值,希望對大家有幫助。
要實現的功能類似下圖,動態新增或刪除p
點選增加可新增一條p 點選刪除可刪除一條p
HTML程式碼如下:(省略CSS樣式程式碼了大笑)
<p class="accordion-inner"> <p class="alert alert-info fade in" ng-repeat="permission in permissions">授权给: <select id="" class="grantees" disabled="" style=" margin-bottom: 3px;" ng-model="permission.grantee"> <option value="everyone">所有人</option> <option value="authenUsers">已认证的用户</option> <option value="me" selected="">我自己</option> </select> <input type="checkbox" checked="" class="permissions" disabled="" ng-model="permission.port1">Open/Download <input type="checkbox" checked="" class="permissions" disabled="" ng-model="permission.port2">View Permissions <input type="checkbox" checked="" class="permissions" disabled="" ng-model="permission.port3">Edit Permissions <button class="btn" type="button" style="float: right;" ng-click="delPermission($index)">删除</button> </p> <p> <button class="btn" type="button" ng-click="addPermission($index)">增加访问许可</button> </p> <br> <p> <button class="btn btn-primary" type="button">保存</button> <button class="btn" type="button">取消</button> </p> </p>
#新增和刪除的JS程式碼分別如下:
//增加许可访问p $scope.permissions = [{grantee: "",port1:"",port2:"",port3:""}]; $scope.addPermission = function($index){ $scope.permissions.splice($index + 1, 0, {grantee:"", port1:"",port2:"",port3:""}); } //删除许可访问p $scope.delPermission = function($index){ $scope.permissions.splice($index, 1); }
上面是我整理給大家的,希望未來會對大家有幫助。
相關文章:
#以上是在angularJS如何實作動態新增,刪除div方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!