jquery 自動切換tab效果代碼

來源:互聯網
上載者:User

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>效果代碼</title>
<script language="網頁特效">
$.tabs = function() { /*main object*/ }

            $.tabs.initialize = function()
            {
                var tabcount = 3, p, str;
                var previoustab = 0; /*0=default*/
                $.tabs.parameters = p = [];
                for (var i = 0; i < arguments.length; i++)
                    p[i] = arguments[i];
                // construct tabbed view
                for (var str = "<div class = 'view' style = 'position:absolute; top:26px; left:2px; width:" + (parseint(p[1])-6) + "; height:" + (parseint(p[2])-4-26) + ";'></div><div style = 'width:" + p[1] + "; height:32px;'>", i = 0; i < p[ tabcount ]; i++)
                    str += "<div class = 'tab' style = 'float:left;' id = '" + i + "'>" + ( p[4][i] ) + "</div>"
                str += "</div>";
                // adjust view
                $("#" + p[0]).css教程({ width:p[1], height:p[2] });
                $("#" + p[0]).html(str);

                // load default view and highlight default tab
                $("#" + p[0] + " .view").html( $("#" + p[5][0]).html() );
                $("#" + p[0] + " #0").addclass("on");

 

                // attach onclick events to all tabs! ~and take care of tab highlighting
                $("#" + p[0] + " .tab").click( function() {
                    var id = this.id;
                    if (id != previoustab) {
                        $("#" + p[0] + " #" + previoustab).removeclass("on");
                        $("#" + p[0] + " #" + id).addclass("on");
                        $("#" + p[0] + " .view").html( $("#" + p[5][id]).html() );
                        previoustab = id;
                    }
                });
            }
</script>
</head>

<body>
外掛程式的jquery對象將採取的主要應用對象,在這種情況下是mytabbedview的id名稱。該代碼會寫這個應用領域本身的內部顯示照顧,所以沒有必要寫任何額外的html。請注意,該代碼正常工作,認為這是一個標籤式的例子,只限於每一個標籤式的設計初始化調用景區之一。這將有可能鞏固提供一個初始化的介面,需要多個分區的多個領域,建立一個單一的網頁標籤的頁面瀏覽量此代碼。與其他外掛程式一樣,我為正宗協會寫的,這微不足道的任務是到網路開發實施自己的網站我的外掛程式代碼。現在,我們已經確定了主要的應用對象mytabbedview,它的下一個步驟的時間。讓我們為我們創造一些標籤查看網頁的內容

<div id = "mytabbedview"></div>
<div id = "page1">page 1<br/>description of jquery tabs plugin</div>
<div id = "page2">page 2<br/>how to use this plugin</div>
<div id = "page3">page 3<br/>download plugin</div>

initializing and executing the jquery tabs plugin

<script type = "text/javascript">
    // initialize plugin code
    $(document).ready(function() {

        jquery.tabs.initialize( "mytabbedview",
                                "300px", "150px",
                                ['description', 'how to use', 'download'],
                                ['page1',       'page2',      'page3'] );

    });
</script>

我們通過主應用程式的預留位置mytabbedview外掛程式tabs.initialize功能。然後,我們通過我們的標籤查看水平和垂直尺寸分別為:300px和150像素。然後,我們通過兩個字串數組。第一個數組表示標籤的名字。第二個數組表示的id標籤的網頁連結到的。如果你想創造超過三個標籤,簡單地擴大在同一陣列的方式都在上面的代碼錶明,不要忘了與其他網頁指定的唯一id的(第1,第2頁,...帕根)。最後一個字標籤視圖介面可以提供一種簡便的方法顯示在一個地方關聯的資訊。這個jquery外掛程式建立,採取所需的最低參數的標籤式的看法。這個外掛程式可以進一步改善提供了一個介面來建立多個標籤在一個頁面上的看法,但我會留給你了。 jquery的再一次顯示了如何輕鬆可以作為複雜的事情,創造一個標籤視圖
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.