本文實(shí)例講述了AngularJS實(shí)現(xiàn)的省市二級(jí)聯(lián)動(dòng)功能。分享給大家供大家參考,具體如下:
成都創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括平南網(wǎng)站建設(shè)、平南網(wǎng)站制作、平南網(wǎng)頁(yè)制作以及平南網(wǎng)絡(luò)營(yíng)銷策劃等。多年來(lái),我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,平南網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到平南省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>www.jb51.net 省市二級(jí)聯(lián)動(dòng)</title> </head> <style> *{ margin:0; padding:0; } .ul{ list-style:none; display:inline-block; } .selectOption ul li{ display:inline-block; width:50px; padding:5px; } ul li:hover{ background-color:#59C0F3; color:#fff; cursor:pointer; } .container{ display:inline-block; } dl{ display: inline-block; } dl dt{ display: inline-block; } .container{ position:relative; text-align: left; vertical-align:top; } .selectBoder{ width:150px; height:20px; margin:0 auto; margin-bottom:5px; cursor:pointer; border:1px solid #808080; padding:2px 5px; font-size:14px; } .selectBoder:hover{ border-color:#59C0F3; } .selectOption:before{ width: 0; height: 0; border-bottom: 50px solid #ffffff; border-left: 50px solid transparent; border-right: 50px solid transparent; } .selectOption{ font-size:14px; position:absolute; background-color: #ffffff; z-index:9999; border:1px solid #eee; width:360px; padding:3px 5px; box-shadow: 5px 5px 10px #888888; } .button{ width:30px; height:30px; display: inline-block; background-color:#59C0F3; text-align:center; line-height: 25px; cursor:pointer; font-size:24px; color:#fff; margin:0 5px; border-radius:30px; } .button:hover{ background-color:#12bb16; } </style> <body ng-app="myApp" ng-controller="myControl"> <div class="inline" ng-repeat = "option in options"> <div class="container"> <dl> <dd class="selectBoder" ng-click="choseP($index)" ng-value="false">{{option.province}}</dd> <dt class="selectOption" ng-if="option.ifShowProvince" ng-mouseleave="leaveProvince(option)"> <ul> <li ng-repeat = " x in province" ng-value="x.value" ng-click="choseProvince($event.target,option)" data-name="{{x.name}}">{{x.name}}</li> </ul> </dt> </dl> </div> <div class="container"> <dl> <dd class="selectBoder" ng-click="choseC($index)" ng-value="false">{{option.city}}</dd> <dt class="selectOption" ng-if="option.ifShowCity" ng-mouseleave="leaveCity(option)"> <ul> <li ng-repeat = "y in option.cities" ng-value="y.value" ng-click="choseCity($event.target,option)" data-name="{{y.name}}">{{y.name}}</li> </ul> </dt> </dl> </div> <span class="button" ng-click="addChose($index)">+</span> <span class="button" ng-click="deleteChose($index)">-</span> </div> </div> </body> <script type="text/javascript" src="../js/jquery-1.8.3.js"></script> <script type="text/javascript" src="../js/angular.min.js"></script> <script type="text/javascript"> var app = angular.module('myApp',[]); app.controller('myControl',function($scope){ $scope.ifShowCity = false; $scope.ifShowProvince = false; $scope.options =[{index:"0",ifShowCity:false,ifShowProvince:false,province:"",city:"",cities:""}]; $scope.leaveProvince = function(option){ $.each($scope.options,function(index,item){ if(option == $scope.options[index]){ $scope.optionIndex = index; } }) $scope.options[$scope.optionIndex].ifShowProvince = false; } $scope.leaveCity = function(option){ $.each($scope.options,function(index,item){ if(option == $scope.options[index]){ $scope.optionIndex = index; } }) $scope.options[$scope.optionIndex].ifShowCity = false; } $scope.choseProvince = function(target,option){ $.each($scope.options,function(index,item){ if(option == $scope.options[index]){ $scope.optionIndex = index; } }) $scope.options[$scope.optionIndex].ifShowProvince = false; $scope.options[$scope.optionIndex].province = target.getAttribute("data-name"); $.each($scope.province,function(index,item){ if(item.value == target.getAttribute("value")){ $scope.options[$scope.optionIndex].cities = item.children; } } ) } $scope.choseCity = function(target,option){ $.each($scope.options,function(index,item){ if(option == $scope.options[index]){ $scope.optionIndex = index; } }) $scope.options[$scope.optionIndex].ifShowCity = false; $scope.options[$scope.optionIndex].city = target.getAttribute("data-name"); } function getPrarms(){ return $scope.options; } $scope.sub = function(){ getPrarms(); } $scope.province = [{ name: "湖北省", value: "01", children: [{ name: "武漢", value: "0101" }, { name: "黃岡", value: "0102" }, { name: "荊州", value: "0103" }, { name: "十堰", value: "0104" }, { name: "黃石", value: "0105" }, { name: "鄂州", value: "0106" }, { name: "咸寧市", value: "0107" }, { name: "襄陽(yáng)市", value: "0108" } ] },{ name: "廣東省", value: "02", children: [{ name: "廣東", value: "0201" }, { name: "深圳", value: "0202" }, { name: "佛山", value: "0203" }, { name: "惠州", value: "0204" }, { name: "東莞", value: "0205" }] },{ name: "河北省", value: "03", children: [{ name: "北京", value: "0301" }, { name: "邯鄲", value: "0302" }, { name: "邢臺(tái)", value: "0303" }, { name: "保定", value: "0304" }, { name: "秦皇島", value: "0305" } ]} ] $scope.choseP = function($index){ $scope.options[$index].ifShowProvince = !$scope.options[$index].ifShowProvince; $scope.options[$index].ifShowCity = false; } $scope.choseC = function($index){ $scope.options[$index].ifShowCity = !$scope.options[$index].ifShowCity; $scope.options[$index].ifShowProvince = false; } $scope.addChose = function($index){ if($scope.options.length < 10){ $scope.options.splice($scope.options.length,0,{ //從最后面添加內(nèi)容 index:$scope.options.length,ifShowCity:false,ifShowProvince:false }); $scope.canDelete = true; }else{ $scope.canAdd = false; } } $scope.deleteChose = function($index){ if($scope.options.length >1){ $scope.options.splice($index,1); //從當(dāng)前行刪除。 } if($index == 1){ $scope.canDelete = false; } } }); </script> </html>
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
標(biāo)題名稱:AngularJS實(shí)現(xiàn)的省市二級(jí)聯(lián)動(dòng)功能示例【可對(duì)選項(xiàng)實(shí)現(xiàn)增刪】-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://www.rwnh.cn/article42/cespec.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站內(nèi)鏈、網(wǎng)站維護(hù)、企業(yè)網(wǎng)站制作、網(wǎng)站改版、網(wǎng)站營(yíng)銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容