AngularJS實現資料列表的增加、刪除和上移下移等功能執行個體_AngularJS

來源:互聯網
上載者:User

效果圖

執行個體代碼

<!DOCTYPE html><html lang="en" ng-app="myapp" ng-controller="myCtrl"><head> <meta charset="UTF-8"> <title>Title</title> <style> *{margin:0;padding:0; list-style: none;font-size:12px;} .clearfix{overflow: hidden;display:block;clear:both} .clearfix:after{zoom:1} .relation{margin-top:7px;font:14px/38px "微軟雅黑"; height: 38px; background: #f8f8f8; padding-left: 26px; color: #666;} .relation li{ margin-top: 5px;float:left;padding-left:50px;cursor:pointer;text-decoration: double} .relation li:hover{color:#f00}; .tableMain li{float:left;padding:5px 10px;width:50px} .ullist1 li.num39{width: 39px; height: 36px;line-height: 36px; text-align: center; float: left; border-right: 1px solid #ddd;} .ullist1 li.num73{width: 73px; height: 36px;line-height: 36px; text-align: center; float: left; border-right: 1px solid #ddd;} .ullist1 li.num85{width: 85px; height: 36px; line-height: 36px; text-align: center; float: left; border-right: 1px solid #ddd;} .ullist1 li.num114{width:140px; height: 36px;line-height: 36px; text-align: center; float: left; border-right: 1px solid #ddd;} .ullist1 li.num122{width:170px; height: 36px;line-height: 36px; text-align: center; float: left; border-right: 1px solid #ddd;} .ullist1 li.num167{width:180px; height: 36px;line-height: 36px; text-align: center; float: left; border-right: 1px solid #ddd;} .ullist1 li.num185{width:185px; height: 36px;line-height: 36px; text-align: center; float: left; border-right: 1px solid #ddd;} .ullist1 li.num70{width:70px;height: 36px;line-height: 36px; text-align: center; float: left; border-right: 1px solid #ddd;} .ullist1 li.num103{width:183px; height: 36px;line-height: 36px; text-align: center; float: left; border-right: 1px solid #ddd;} .ullist1 li.num97{width:160px; height: 36px;line-height: 36px; text-align: center; float: left; border-right: 1px solid #ddd;} .ulConter1 li.num39{width: 39px;height: 42px; line-height: 42px; float: left; border-right: 1px solid #ddd;} .ulConter1 li.num73{width: 73px; height: 42px; line-height: 42px; float: left; border-right: 1px solid #ddd;} .ulConter1 li.num85{width: 85px; height: 42px; line-height: 42px; float: left; border-right: 1px solid #ddd;} .ulConter1 li.num114{width:140px; height: 42px; line-height: 42px; float: left; border-right: 1px solid #ddd;} .ulConter1 li.num122{width:170px; height: 42px; line-height: 42px; float: left; border-right: 1px solid #ddd;} .ulConter1 li.num167{width:180px; height: 42px; line-height: 42px; float: left; border-right: 1px solid #ddd;} .ulConter1 li.num185{width:185px; height: 42px; line-height: 42px; float: left; border-right: 1px solid #ddd;} .ulConter1 li.num70{width:70px; height: 42px; line-height: 42px; float: left; border-right: 1px solid #ddd;} .ulConter1 li.num103{width:183px; height: 42px; line-height: 42px; float: left; border-right: 1px solid #ddd;} .ulConter1 li.num97{width:160px; height: 42px; line-height: 42px; float: left; border-right: 1px solid #ddd;} .ulConter1 li.num39 input{ width:19px; height: 19px; margin:11px; border: 1px solid #ddd; } .ulConter1 li.num73 input{ width:68px; border: 1px solid #ddd; margin: 2px;line-height: 32px; height: 32px;} .ulConter1 li.num85 input{ width:80px; border: 1px solid #ddd; margin: 2px;line-height: 32px; height: 32px;} .ulConter1 li.num114 input{ width:135px; border: 1px solid #ddd; margin: 2px;line-height: 32px; height: 32px;} .ulConter1 li.num122 input{ width:165px; border: 1px solid #ddd; margin: 2px;line-height: 32px; height: 32px;} .ulConter1 li.num167 input{ width:175px; border: 1px solid #ddd; margin: 2px;line-height: 32px; height: 32px;} .ulConter1 li.num185 input{ width:180px; border: 1px solid #ddd; margin: 2px;line-height: 32px; height: 32px;} .ulConter1 li.num70 input{ width:65px; border: 1px solid #ddd; margin: 2px;line-height: 32px; height: 32px;} .ulConter1 li.num103 input{ width:178px; border: 1px solid #ddd; margin: 2px;line-height: 32px; height: 32px;} .ulConter1 li.num97 input{ width:150px; border: 1px solid #ddd; margin: 2px;line-height: 32px; height: 32px;} </style> <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script></head><body><ul class="relation clearfix"> <li class="news" ng-click="others.addContact()">新增</li> <li class="dele" ng-click="others.deleContact()">刪除</li> <li class="upico" ng-click="others.moveUp()">上移</li> <li class="downico" ng-click="others.moveDown()">下移</li></ul><div class="class="tableMain""> <ol class="clearfix ullist1"> <li class="num39"></li> <li class="num73">連絡人</li> <li class="num85">商務電話</li> <li class="num114">行動電話</li> <li class="num122">QQ</li> <li class="num122">SKYPE</li> <li class="num167">電子郵件</li> </ol> <ul class="ulConter1 clearfix" ng-repeat="item in items" > <li class="num39">  <input type="radio" ng-click="others.selected(item)" name="select"> </li> <li class="num73">  <input type="text" ng-model="item.otherContact"> </li> <li class="num85">  <input type="text" ng-model="item.otherBusinessTel" > </li> <li class="num114">  <input type="text" ng-model="item.otherMobPhone" > </li> <li class="num122">  <input type="text" ng-model="item.otherQQ" > </li> <li class="num122">  <input type="text" ng-model="item.otherSKYPE" > </li> <li class="num167">  <input type="text" ng-model="item.otherEmail"> </li>  </ul></div><script>angular.module('myapp',[]).controller('myCtrl',function($scope){ $scope.items=[]; $scope.others={ selectedItem:{}, selected:function(item){  this.selectedItem=item; }, //增加 addContact:function(){  $scope.items.push({  otherContact:'',  otherBusinessTel:'',  otherMobPhone:'',  otherQQ:'',  otherSKYPE:'',  otherEmail:'',  otherDeliveryAddress:'',  otherSex:'',  otherDepartment:''  }); }, //刪除; deleContact:function(){  var index=$scope.items.indexOf(this.selectedItem);  $scope.items.splice(index,1); }, //上移; moveUp:function(){  var index=$scope.items.indexOf(this.selectedItem);  var tmp=angular.copy($scope.items[index-1]);  if(index==0){  alert('已經是第一個了,不能再向上移動了!');  return ;  }  $scope.items[index-1]=$scope.items[index];  $scope.items[index]=tmp; }, //下移; moveDown:function(){  var index=$scope.items.indexOf(this.selectedItem);  if(index==$scope.items.length-1){  alert('已經是最後一個了,不能再向下移動了!');  return ;  }  var tmp=angular.copy($scope.items[index+1]);  $scope.items[index+1]=$scope.items[index];  $scope.items[index]=tmp; } }})</script></body></html>

總結

以上就是這篇文章的全部內容,大家可以自己實踐後看下效果,這樣更利於大家的理解和學習,希望本文對大家學習或使用AngularJS能有所協助。如果有疑問可以留言交流,謝謝大家對雲棲社區的支援。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.