AngularJS – Tab 介紹篇
為了方便文章閱讀,本篇將Tab翻譯成頁籤
這個案例的複雜度會比較前面高一些,因為它不僅僅是使用我們一直提到的AngularJS,為了要製作頁面上面的一些互動效果,還加入了Bootstrape這個通常被用來當RWD的框架,不過也僅僅是套用了幾個類別,所以大家也不用太擔心,接下來我們先看一下這個案例最後希望要達成的效果頁面。
在看過了目標頁面後,我們先來了解一下需要怎麼樣架構我們的HTML,首先是CSS和Javascript的引入,分別是AngularJS、jQuery、Bootstrap CSS以及Javascript:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> <script src="https://code.jquery.com/jquery.min.js"></script> <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
在HTML文件中,必須有項目清單標籤ul、li,而在ul標籤中需套用nav nav-pills這兩個css類別,這兩個類別是由Bootstrape的css所提供的,li標籤是包覆著超連結的a標籤,下圖案例是希望可以產生三個頁籤。
在a標籤中加入ng-click=”tab = 1″、ng-click=”tab = 2″、ng-click=”tab = 3″去設定當使用者按下連結後tab變數會隨著變化,另外為了方便觀察是否成功,在頁面上利用表達式將tab變數顯示出來。
若一切順利,在我們按下不同的頁籤連結時,畫面上應該會有數字上面的變化。
接下來開始製作點選頁籤後的內容頁面,同樣的內容頁面也應該有三個才對,在HTML中產生三個div,其中套用Bootstrape所提供的CSS panel類別,div的內容部分可依照需求置入。
在div中利用ng-show去判斷tab變數的值來切換顯示。
完成後,在我們點選不同的連結時,內容的部分也應該會隨著變動。
接下來我們在section標籤中設定ng-init=”tab=1″的屬性來決定tab變數的初始值。
接下來在li內新增ng-class的屬性,依tab變數的值來切換active的CSS屬性(該屬性由Bootstrape提供樣式),其中三個連續的等號是判斷該變數與值完全相同的意思。
這個動作的目的是希望當網友點選之後,可以如下圖所示,清楚的標示目前頁面上所顯示的是第幾個項目。
到目前為止,大概就完成了我們希望呈現的頁籤效果,大家可以透過JS Bin來測試看看到目前為止的程式碼。
<!DOCTYPE html> <html ng-app> <head> <meta name="description" content="AngularJS Tabs Example 1"> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> <script src="//code.jquery.com/jquery.min.js"></script> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> <meta charset="utf-8"> <title>AngularJS Tabs Example 1</title> </head> <body> <section ng-init="tab=1"> <ul class="nav nav-pills"> <li ng-class="{ active: tab===1 }"> <a href="" ng-click="tab=1">滑鼠墊</a> </li> <li ng-class="{ active: tab===2 }"> <a href="" ng-click="tab=2">馬克杯</a> </li> <li ng-class="{ active: tab===3 }"> <a href="" ng-click="tab=3">杯墊</a> </li> </ul> <div class="panel" ng-show="tab===1"> <h4>馬老師雲端研究室 滑鼠墊</h4> <p>產品介紹...</p> </div> <div class="panel" ng-show="tab===2"> <h4>馬老師雲端研究室 馬克杯</h4> <p>產品介紹...</p> </div> <div class="panel" ng-show="tab===3"> <h4>馬老師雲端研究室 杯墊</h4> <p>產品介紹...</p> </div> </section> </body> </html>
在看完了上面的案例之後,我們可以觀察到程式邏輯判斷的部分都是直接撰寫在HTML頁面上,那如果我們要把邏輯判斷的部分從HTML拆開寫到Javascript檔又應該要如何處理呢?首先,不用說的當然是必須要有應用程式的建立以及控制器囉!下圖中我們開始新增控制器,並且在section標籤中,輸入ng-controller=”panelController as panel”的屬性,相信在看了前幾篇教學的同學們對於這樣的項目是再熟悉不過了!接下來在控制器中,決定tab變數的初始值,就可以把原來的ng-init屬性刪除了。
在ng-click後去執行控制器中的selectTab函數,並且針對該函數帶入不同的值,利用帶入的值來改變tab變數值。
在ng-click後去執行控制器中的isSelected函數,也帶出不同的值給函數,讓函數可以回傳tab===1或2、3這樣的內容給ng-show使用。
這樣一來我們邏輯判斷的部分就會和網頁內容有所區隔,大家也可以透過JS Bin來測試這樣的程式結構。
<!DOCTYPE html> <html ng-app="store"> <head> <meta name="description" content="AngularJS Tabs Example 2"> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> <script src="//code.jquery.com/jquery.min.js"></script> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> <meta charset="utf-8"> <title>AngularJS Tabs Example 2</title> </head> <body> <section ng-controller="PanelController as panel"> <ul class="nav nav-pills"> <li ng-class="{ active: panel.isSelected(1) }"> <a href="" ng-click="panel.selectTab(1)">滑鼠墊</a> </li> <li ng-class="{ active: panel.isSelected(2) }"> <a href="" ng-click="panel.selectTab(2)">馬克杯</a> </li> <li ng-class="{ active: panel.isSelected(3) }"> <a href="" ng-click="panel.selectTab(3)">杯墊</a> </li> </ul> <div class="panel" ng-show="panel.isSelected(1)"> <h4>馬老師雲端研究室 滑鼠墊</h4> <p>產品介紹...</p> </div> <div class="panel" ng-show="panel.isSelected(2)"> <h4>馬老師雲端研究室 馬克杯</h4> <p>產品介紹...</p> </div> <div class="panel" ng-show="panel.isSelected(3)"> <h4>馬老師雲端研究室 杯墊</h4> <p>產品介紹...</p> </div> </section> </body> </html>
(function(){ var app = angular.module('store', []); app.controller('PanelController', function(){ this.tab = 1; this.selectTab = function(setTab){ this.tab = setTab; }; this.isSelected = function(checkTab){ return this.tab === checkTab; }; }); })();
What this high school senior wants adults to know about classroom phone bans
личный юрист сбербанк
стоимость услуг медиатора
сбербанк официальный сайт для юр лиц
сбер услуги для мастеров
онлайн юристы бесплатно
сайт юристов онлайн
https www sberbank ru ru s m business exdocssearch
юрист сбербанка
ооо сбер лигал
кредиты сбербанк онлайн
When my friends and I walked into homeroom on the first day of school this year, my teacher told all of us to put our phones in a black plastic box on an old desk by the classroom door.
Handing over our phones during class is an official school policy, and my teachers always make this announcement at the beginning of the school year. But teachers would usually forget about the box by third period on the first day, never to be mentioned again by the second day of school. This year, however, the policy stuck that entire first day — and every day since.
I asked my Latin teacher why the school was suddenly getting so strict on phones. It turns out that over the summer most of the teachers had read social psychologist Jonathan Haidt’s book “The Anxious Generation: How the Great Rewiring of Childhood Is Causing an Epidemic of Mental Illness.”
Haidt, the Thomas Cooley Professor of Ehtical Leadership at New York University Stern School of Business, argues that a phone-based childhood leads to mentally unhealthy kids who are unprepared for life and, in my Latin teacher’s words, it “really freaked us out.” Teachers were serious about taking our phones now.
It’s not just causing trouble at my school. Some 72% of public high school teachers in the United States say that cell phone distraction among their students is a major problem, according to a study published by the Pew Research Center in April. In high schools that already have cell phone policies, 60% of teachers say that the policies are very or somewhat difficult to enforce, the same study reported.
Several states have passed laws attempting to restrict cell phone use in schools, and California Gov. Gavin Newsom recently signed legislation requiring school districts to regulate cell phone use. At least seven of the 20 largest school districts in the nation have either banned phones during the school day or plan to do so.
https://gabapentin.auction/# neurontin 100mg discount
The WNBA is having a real moment – Caitlin Clark and the league’s historic season by the numbers
юрист по семейному праву консультация москва
консультация юриста по семейным вопросам
консультация семейного юриста
юридические услуги собственность
помощь адвоката по семейным делам
сопровождение сделок с недвижимостью цена
персональные данные сбербанк
юрист по недвижимости москва консультации
как выбрать юриста по недвижимости
услуги адвоката по семейным делам
When many of us hear the “Fall Classic,” we automatically think of baseball’s World Series. I’m not sure that will be the case for future generations.
Yes, I’m being somewhat provocative with that line, but the WNBA Finals have arrived on the heels of what can only be described as a historic season for the league. Across a metric of statistics, it’s clear that America’s interest in the WNBA is at the highest point this century in large part because of Indiana Fever star Caitlin Clark.
Let’s start simple: Google searches. They’ve been higher this WNBA season, starting with the draft in April, than at any point since we’ve had data (2004). Searches for the WNBA are up over 300% compared to last season, up over 850% compared to five seasons ago, and have risen nearly 1,400% from a decade ago.
That is, the WNBA has been rising, and this year it really took off.
This interest has translated into revenue for the league. Attendance is up a staggering 48% from 2023. There wasn’t a single team with an average regular season home attendance of five figures (10,000+) in 2023. This season, there were six.
Leading the charge was Clark’s Fever. A little more than 4,000 people attended their average game in 2023, which ranked them second to last. This season, more than 17,000 did, a 319% rise that put them far and away ahead of any other WNBA team and ahead of five NBA teams, including the hometown Indiana Pacers.
We see the same pattern in merchandise. Sales are up 600% from last year. This includes the boost from rookie sensations Clark, who had the best-selling jersey, and Angel Reese of the Chicago Sky, who had the second-best-selling jersey.
Тут делают продвижение разработка мед сайтов создание сайта для клиники
Тут делают продвижение seo медицина seo. медицинских. сайтов
This is the right site for everyone who hopes to understand this topic. You understand a whole lot its almost tough to argue with you (not that I really would want to…HaHa). You definitely put a fresh spin on a topic that’s been written about for decades. Wonderful stuff, just wonderful.
Отличный сайт! Всем рекомендую!Оптика СПб
u0101 kia код ошибки и расшифровка потери связи с tcm
веном 2 фильм смотреть онлайн фильм веном полный веном 2 смотреть в хорошем качестве
zithromax 250 mg australia zithromax 250 mg australia buy cheap zithromax online
Great blog you have here.. It’s difficult to find good quality writing like yours nowadays. I truly appreciate people like you! Take care!!
Профессиональный сервисный центр по ремонту моноблоков iMac в Москве.
Мы предлагаем: сервис по ремонту imac
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
http://www.askmap.net/location/7105986/vietnam/ko66vip
пин ап казино https://pinupaz.bid/# pinup azerbaycan
пин ап казахстан
фильм веном 2 смотреть фильм бесплатно веном смотреть кино веном 2
pin up: пин ап кз – пин ап казино
pin-up kazino pin up casino pin up
кино веном 2 веном 2 смотреть онлайн бесплатно в хорошем качестве смотреть фильм веном 2
http://pinupaz.bid/# pin-up casino giris
пин ап казино вход https://pinupkz.tech/# пин ап казино онлайн
pin up казино
Профессиональный сервисный центр ближайшая мастерская по ремонту телефонов сервисный центр по ремонту телефонов
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем: ремонт крупногабаритной техники в воронеже
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
pin up casino giris: pin up casino guncel giris – pin-up casino
pin up casino giris pin up guncel giris pin up giris
I’m impressed, I must say. Seldom do I encounter a blog that’s both equally educative and entertaining, and let me tell you, you’ve hit the nail on the head. The issue is something which too few men and women are speaking intelligently about. Now i’m very happy that I stumbled across this during my search for something relating to this.
Тут делают продвижение создать сайт медицинского центра создание сайтов для клиники
1win сайт https://edulike.uz/
Also visit my website highstakes Casino Download
http://pinupaz.bid/# pin up casino
pin up kz http://pinupkz.tech/# pin up kz
пин ап казахстан