angularjs 切換tab頁的一個方法

來源:互聯網
上載者:User

標籤:

tab條的 css:

 1 .floor-tab-li { 2     float: left; 3     padding: 6px 12px; 4     font-size: 14px; 5     font-weight: normal; 6     line-height: 1.42857143; 7     text-align: center; 8     white-space: nowrap; 9     vertical-align: middle;10     border: 1px solid #ddd;11     background-color: #ffffff;12     border-radius: 3px;13     margin-right: 10px;14     color: #4c5667;15     cursor:pointer;16 }17 18 .tabActive {19     color: #fff;20     background-color: #B36A46;21     border: 1px solid #B36A46;22 }

HTML 程式碼

<div class="tab">    <ul class="floor-tab fix">        <li class="floor-tab-li" ng-repeat="tab in tabs"            ng-class="{tabActive:isActiveTab(tab.url)}"            ng-click="onClickTab(tab)">            {{tab.title}}        </li>    </ul></div><div class="card-box">    <div ng-include="currentTab"></div></div><script type="text/ng-template" id="a.html">        //a.html</script><script type="text/ng-template" id="b.html">        //b.html</script>

javascript

//tab        self.scope.tabs = [            {                title: ‘標題1‘,                url: ‘a.html‘            },            {                title: ‘標題2‘,                url: ‘b.html‘            }        ];        //預設項        self.scope.currentTab = ‘a.html‘;        self.scope.onClickTab = function (tab) {            self.scope.currentTab = tab.url;        };        self.scope.isActiveTab = function(tabUrl) {            return tabUrl == self.scope.currentTab;        }

註:倘若更改了資料重新整理資料時讓頁面顯示那個頁面,比如b.html;在請求資料介面的回調中添加一句:

 self.scope.currentTab = ‘b.html‘;

angularjs 切換tab頁的一個方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.