angularjs實現(xiàn)Tab欄切換效果
本文實例為大家分享了angularjs實現(xiàn)Tab欄切換效果的具體代碼,供大家參考,具體內(nèi)容如下
如圖所示
選中后提交的實例代碼:
<!DOCTYPE html> <html lang="en" ng-app="myApp"> ? ? <head> ? ? ? ? <meta charset="utf-8"> ? ? ? ? <script type="text/javascript" src="asserts/angular.js"></script> ? ? ? ? <style type="text/css"> ? ? ? ? ? ? .div-img{ ? ? ? ? ? ? ? ? float: left; ? ? ? ? ? ? ? ? margin:5px; ? ? ? ? ? ? } ? ? ? ? ? ? img{ ? ? ? ? ? ? ? ? width:200px; ? ? ? ? ? ? ? ? height:200px; ? ? ? ? ? ? ? ? border:2px solid pink; ? ? ? ? ? ? } ? ? ? ? ? ? .kongxin{ ? ? ? ? ? ? ? ? margin:0 auto; ? ? ? ? ? ? ? ? background-color: #ddd; ? ? ? ? ? ? ? ? width:20px; ? ? ? ? ? ? ? ? height:20px; ? ? ? ? ? ? ? ? border-radius: 10px; ? ? ? ? ? ? } ? ? ? ? ? ? .shixin{ ? ? ? ? ? ? ? ? margin:0 auto; ? ? ? ? ? ? ? ? background-color: red; ? ? ? ? ? ? ? ? width:20px; ? ? ? ? ? ? ? ? height:20px; ? ? ? ? ? ? ? ? border-radius: 10px; ? ? ? ? ? ? } ? ? ? ? ? ? .pic-title{ ? ? ? ? ? ? ? ? text-align: center; ? ? ? ? ? ? } ? ? ? ? </style> ? ? </head> ? ? <body ng-controller="myController"> ? ? ? ? <div class="div-img" ng-repeat="picItem in picLists"> ? ? ? ? ? ? <div class="pic-title" ng-bind="picItem.title"></div> ? ? ? ? ? ? <img ng-src="{{picItem.url}}" alt="顯示圖片" ng-click="checkItems(picItem)">? ? ? ? ? ? ? <div class="kongxin" ng-if="picItem.selected"></div> ? ? ? ? ? ? <div class="shixin" ng-if="picItem.checked"></div> ? ? ? ? </div> ? ? ? ? <div> ? ? ? ? ? ? <input type="submit" value="點此提交" ng-click="choosePic()"> ? ? ? ? </div> ? ? ? ? <div ng-bind="url"></div> ? ? </body> ? ? <script type="text/javascript"> ? ? var myApp=angular.module('myApp', []); ? ? myApp.controller("myController",['$scope',function ($scope){ ? ? ? ? $scope.picLists=[ ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? picName:"圖片一", ? ? ? ? ? ? ? ? ? ? url:'imgs/img1.jpg', ? ? ? ? ? ? ? ? ? ? title:'圖片標題1' ? ? ? ? ? ? ? ? },{ ? ? ? ? ? ? ? ? ? ? picName:"圖片2", ? ? ? ? ? ? ? ? ? ? url:'imgs/img2.jpg', ? ? ? ? ? ? ? ? ? ? title:'圖片標題2' ? ? ? ? ? ? ? ? },{ ? ? ? ? ? ? ? ? ? ? picName:"圖片3", ? ? ? ? ? ? ? ? ? ? url:'imgs/img3.jpg', ? ? ? ? ? ? ? ? ? ? title:'圖片標題3' ? ? ? ? ? ? ? ? },{ ? ? ? ? ? ? ? ? ? ? picName:"圖片4", ? ? ? ? ? ? ? ? ? ? url:'imgs/img4.jpg', ? ? ? ? ? ? ? ? ? ? title:'圖片標題4' ? ? ? ? ? ? ? ? },{ ? ? ? ? ? ? ? ? ? ? picName:"圖片5", ? ? ? ? ? ? ? ? ? ? url:'imgs/img5.jpg', ? ? ? ? ? ? ? ? ? ? title:'圖片標題5' ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ] ? ? ? ?? ? ? ? ? angular.forEach($scope.picLists,function(item){ ? ? ? ? ? ? item.selected=true; ? ? ? ? }) ? ? ? ? $scope.checkItems=function(picItem){ ? ? ? ? ? ? angular.forEach($scope.picLists,function(item){ ? ? ? ? ? ? ? ? if(item.title==picItem.title){ ? ? ? ? ? ? ? ? ? ? item.checked=true; ? ? ? ? ? ? ? ? ? ? item.selected=false; ? ? ? ? ? ? ? ? }else{ ? ? ? ? ? ? ? ? ? ? item.checked=false; ? ? ? ? ? ? ? ? ? ? item.selected=true; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? }) ? ? ? ? }; ? ? ? ? $scope.choosePic=function(){ ? ? ? ? ? ? angular.forEach($scope.picLists,function(item){ ? ? ? ? ? ? ? ? if(item.checked){ ? ? ? ? ? ? ? ? ? ? $scope.url=item.url; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? }) ? ? ? ? } ? ? }]) ? ? </script> </html>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Angular ng-repeat 對象和數(shù)組遍歷實例
這篇文章主要介紹了Angular ng-repeat對象和數(shù)組遍歷的相關(guān)資料,并附代碼示例,需要的朋友可以參考下2016-09-09詳解為Angular.js內(nèi)置$http服務(wù)添加攔截器的方法
所謂攔截器就是在目標達到目的地之前對其進行處理以便處理結(jié)果更加符合我們的預(yù)期。Angular的$http攔截器是通過$httpProvider.interceptors數(shù)組定義的一組攔截器,每個攔截器都是實現(xiàn)了某些特定方法的Factory。本文就介紹了為Angular.js內(nèi)置$http服務(wù)添加攔截器的方法。2016-12-12angularjs使用directive實現(xiàn)分頁組件的示例
本篇文章主要介紹了angularjs使用directive實現(xiàn)分頁組件的示例,具有一定的參考價值,有興趣的可以了解一下。2017-02-02Angular+Ionic使用queryParams實現(xiàn)跳轉(zhuǎn)頁傳值的方法
這篇文章主要介紹了Angular+Ionic使用queryParams實現(xiàn)跳轉(zhuǎn)頁傳值的方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09AngularJS在IE下取數(shù)據(jù)總是緩存問題的解決方法
這篇文章主要介紹了AngularJS在IE下取數(shù)據(jù)總是緩存問題的解決方法,分析了問題的原因及AngularJS設(shè)置禁止IE對ajax緩存的實現(xiàn)方法,需要的朋友可以參考下2016-08-08Angular.js中上傳指令ng-upload的基本使用教程
這篇文章主要給大家介紹了關(guān)于Angular.js中上傳指令ng-upload的基本使用方法,文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面跟著小編來一起學習學習吧。2017-07-07AngularJS教程之MVC體系結(jié)構(gòu)詳解
本文主要講解AngularJS MVC體系結(jié)構(gòu),這里提供詳細的教程供大家學習參考,有需要的小伙伴可以參考下2016-08-08