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)文章
angular inputNumber指令輸入框只能輸入數(shù)字的實(shí)現(xiàn)
這篇文章主要介紹了angular inputNumber指令輸入框只能輸入數(shù)字的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
Angular 4.x+Ionic3踩坑之Ionic3.x pop反向傳值詳解
這篇文章主要給大家介紹了關(guān)于Angular 4.x+Ionic3踩坑之Ionic3.x pop反向傳值的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-03-03
AngularJS入門教程之學(xué)習(xí)環(huán)境搭建
這篇文章主要介紹了AngularJS入門教程之學(xué)習(xí)環(huán)境搭建,本教程將指導(dǎo)您完成一個(gè)簡(jiǎn)單的應(yīng)用程序創(chuàng)建過(guò)程,包括編寫和運(yùn)行單元測(cè)試、不斷地測(cè)試應(yīng)用,需要的朋友可以參考下2014-12-12
淺談Angular4實(shí)現(xiàn)熱加載開發(fā)旅程
本篇文章主要介紹了淺談Angular4實(shí)現(xiàn)熱加載開發(fā)旅程,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09
Angular.js指令學(xué)習(xí)中一些重要屬性的用法教程
這篇文章主要給大家介紹了關(guān)于Angular.js指令學(xué)習(xí)中一些重要屬性的用法教程,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-05-05
AngularJS中的Directive實(shí)現(xiàn)延遲加載
延遲加載通常是直到用戶交互時(shí)才加載,那么如何實(shí)現(xiàn)延時(shí)加載的呢?下面通過(guò)本文一起學(xué)習(xí)AngularJS中的Directive實(shí)現(xiàn)延遲加載,對(duì)angularjs延時(shí)加載相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-01-01
在AngularJS中如何使用谷歌地圖把當(dāng)前位置顯示出來(lái)
這篇文章給的大家介紹在AngularJS中如何使用谷歌地圖把當(dāng)前位置顯示出來(lái),本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,對(duì)angularjs 谷歌地圖相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-01-01
AngularJS bootstrap啟動(dòng)詳解及實(shí)例代碼
這篇文章主要介紹了AngularJS bootstrap啟動(dòng)的知識(shí),這里整理了相關(guān)資料及簡(jiǎn)單實(shí)例代碼,,需要的朋友可以參考下2016-09-09

