這篇文章將為大家詳細(xì)講解有關(guān)angular框架如何實(shí)現(xiàn)全選與單選chekbox,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)新互聯(lián)專(zhuān)注于和順企業(yè)網(wǎng)站建設(shè),自適應(yīng)網(wǎng)站建設(shè),商城網(wǎng)站定制開(kāi)發(fā)。和順網(wǎng)站建設(shè)公司,為和順等地區(qū)提供建站服務(wù)。全流程按需開(kāi)發(fā),專(zhuān)業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專(zhuān)業(yè)和態(tài)度為您提供的服務(wù)
1)頁(yè)面內(nèi)容(靜態(tài)頁(yè))
<ul class='list-inline my-list-inline'> <li class="action-check" ng-class="{'active':allHasChoice}" ng-click="clicktarget(true,tmp,dataList)"> <li>中文名稱(chēng)</li> <li>英文名稱(chēng)</li> <li>申請(qǐng)人類(lèi)型</li> <ul> <div class="list-data"> <table> <tbody> <tr ng-repeat="tmp in dataList track by tmp.idTell" ng-class="{true:'active',false:''}[targetChoice[tmp.idTell]==true]" ng-click="ctmlicktarget(false,tmp,dataList)" > <td> <span class="choice-icon"></span> <span class="company-name over-flow-handel-style" title="{{tmp.chineseName}}" ng-bind="tmp.cineseName"></span> </td> <td> <span class="english-name over-flow-handel-style" title="{{tmp.englishName}}" ng-bind="tmp.englishName"></span> </td> <td> <span class="english-name over-flow-handel-style" title="{{tmp.abbreviation}}" ng-bind="tmp.abbreviation"></span> </td> </tr> </tbody> </table>
2)js代碼
首先當(dāng)然有一個(gè)參數(shù)數(shù)組,用于經(jīng)營(yíng)經(jīng)營(yíng)渲染頁(yè)面:
$scope.dataList=[ {'chineseName':'百度科技','englishName':'baidukeji','abbreviation':'小度','idTell':'bd'}, {'chineseName':'小牛科技','englishName':'xiaoniukeji','abbreviation':'小牛','idTell':'xn'}, {'chineseName':'京東科技','englishName':'jdkeji','abbreviation':'小京','idTell':'xj'}, {'chineseName':'順風(fēng)科技','englishName':'sfkeji','abbreviation':'小風(fēng)','idTell':'xf'}, {'chineseName':'阿里科技','englishName':'alkeji','abbreviation':'小里','idTell':'xl'}, {'chineseName':'淘寶科技','englishName':'tbkeji','abbreviation':'小寶','idTell':'xb'}, {'chineseName':'天貓科技','englishName':'tmkeji','abbreviation':'小貓','idTell':'xm'} ];
定義一個(gè)數(shù)組用于存儲(chǔ),選中的選項(xiàng)
$scope.targetChoice=[];
定義一個(gè)很簡(jiǎn)單的方法:用于操作單選,全選的效果實(shí)現(xiàn)
$scope.clicktarget=function(isAllChoiceBtn,tmp,dataList){ //isAllChoiceBtn:用于表示用戶(hù)點(diǎn)擊的是否是全選按鈕,tmp:是數(shù)據(jù)集合中的一個(gè)數(shù)據(jù)對(duì)象 var count=0;//記錄被選中的子選項(xiàng)的個(gè)數(shù) //說(shuō)明用戶(hù)點(diǎn)擊的不是“全選”按鈕 isAllChoiceBtn==false?(function(){ //當(dāng)前選項(xiàng)取反 $scope.targetChoice[tmp.idTell]=!$scope.targetChoice[tmp.idTell]; //遍歷數(shù)據(jù)集合,統(tǒng)計(jì)已經(jīng)被購(gòu)中的單選項(xiàng) angular.foreach(dataList,function(v,k){ $scope.targetChoice[v.idTell]&& count++; }); //如果count等于數(shù)據(jù)集合得長(zhǎng)度,說(shuō)明所有的單選被購(gòu)中 count==dataList.length && $scope.allHasChoice=true:$scope.allHasChoice==false; })() //說(shuō)明點(diǎn)擊的"全選"按鈕 :(function(){ $scope.allHasChoice=!$scope.allHasChoice;//狀態(tài)取反 $scope.allHasChoice==false? //說(shuō)明取消全選 :angular.forEach(dataList,function(v,k){ $scope.targetChoice[v.idTell]=$scope.allHasChoice; count=0; }) //說(shuō)明選中全選 :angular.forEach(dataList,function(v,k){ $scope.targetChioce[v.idTell]=$scope.allHasChoice; count++; }); })() }
關(guān)于“angular框架如何實(shí)現(xiàn)全選與單選chekbox”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
標(biāo)題名稱(chēng):angular框架如何實(shí)現(xiàn)全選與單選chekbox
文章分享:http://aaarwkj.com/article12/phdigc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷(xiāo)、網(wǎng)站制作、外貿(mào)建站、品牌網(wǎng)站制作、網(wǎng)站改版、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)