angularjs實(shí)現(xiàn)Tab欄切換效果
本文實(shí)例為大家分享了angularjs實(shí)現(xiàn)Tab欄切換效果的具體代碼,供大家參考,具體內(nèi)容如下
如圖所示

選中后提交的實(shí)例代碼:
<!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="點(diǎn)此提交" 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:'圖片標(biāo)題1'
? ? ? ? ? ? ? ? },{
? ? ? ? ? ? ? ? ? ? picName:"圖片2",
? ? ? ? ? ? ? ? ? ? url:'imgs/img2.jpg',
? ? ? ? ? ? ? ? ? ? title:'圖片標(biāo)題2'
? ? ? ? ? ? ? ? },{
? ? ? ? ? ? ? ? ? ? picName:"圖片3",
? ? ? ? ? ? ? ? ? ? url:'imgs/img3.jpg',
? ? ? ? ? ? ? ? ? ? title:'圖片標(biāo)題3'
? ? ? ? ? ? ? ? },{
? ? ? ? ? ? ? ? ? ? picName:"圖片4",
? ? ? ? ? ? ? ? ? ? url:'imgs/img4.jpg',
? ? ? ? ? ? ? ? ? ? title:'圖片標(biāo)題4'
? ? ? ? ? ? ? ? },{
? ? ? ? ? ? ? ? ? ? picName:"圖片5",
? ? ? ? ? ? ? ? ? ? url:'imgs/img5.jpg',
? ? ? ? ? ? ? ? ? ? title:'圖片標(biāo)題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>以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
angularjs實(shí)現(xiàn)與服務(wù)器交互分享
AngularJS是Google開(kāi)發(fā)的純客戶端JavaScript技術(shù)的WEB框架,用于擴(kuò)展、增強(qiáng)HTML功能,它專為構(gòu)建強(qiáng)大的WEB應(yīng)用而設(shè)計(jì)。2014-06-06
Angular ng-repeat 對(duì)象和數(shù)組遍歷實(shí)例
這篇文章主要介紹了Angular ng-repeat對(duì)象和數(shù)組遍歷的相關(guān)資料,并附代碼示例,需要的朋友可以參考下2016-09-09
詳解為Angular.js內(nèi)置$http服務(wù)添加攔截器的方法
所謂攔截器就是在目標(biāo)達(dá)到目的地之前對(duì)其進(jìn)行處理以便處理結(jié)果更加符合我們的預(yù)期。Angular的$http攔截器是通過(guò)$httpProvider.interceptors數(shù)組定義的一組攔截器,每個(gè)攔截器都是實(shí)現(xiàn)了某些特定方法的Factory。本文就介紹了為Angular.js內(nèi)置$http服務(wù)添加攔截器的方法。2016-12-12
Angularjs驗(yàn)證用戶輸入的字符串是否為日期時(shí)間
這篇文章主要介紹了Angularjs驗(yàn)證用戶輸入的字符串是否為日期時(shí)間,需要的朋友可以參考下2017-06-06
angularjs使用directive實(shí)現(xiàn)分頁(yè)組件的示例
本篇文章主要介紹了angularjs使用directive實(shí)現(xiàn)分頁(yè)組件的示例,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-02-02
Angular+Ionic使用queryParams實(shí)現(xiàn)跳轉(zhuǎn)頁(yè)傳值的方法
這篇文章主要介紹了Angular+Ionic使用queryParams實(shí)現(xiàn)跳轉(zhuǎn)頁(yè)傳值的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09
AngularJS在IE下取數(shù)據(jù)總是緩存問(wèn)題的解決方法
這篇文章主要介紹了AngularJS在IE下取數(shù)據(jù)總是緩存問(wèn)題的解決方法,分析了問(wèn)題的原因及AngularJS設(shè)置禁止IE對(duì)ajax緩存的實(shí)現(xiàn)方法,需要的朋友可以參考下2016-08-08
Angular.js中上傳指令ng-upload的基本使用教程
這篇文章主要給大家介紹了關(guān)于Angular.js中上傳指令ng-upload的基本使用方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-07-07
AngularJS教程之MVC體系結(jié)構(gòu)詳解
本文主要講解AngularJS MVC體系結(jié)構(gòu),這里提供詳細(xì)的教程供大家學(xué)習(xí)參考,有需要的小伙伴可以參考下2016-08-08

