jQuery學習筆記----用jquery實現多選項卡功能

來源:互聯網
上載者:User

Web中用到多選項卡功能的網站有很多,比如163和126郵箱,用過的人知道。本人在那麼多的類似外掛程式中,目前碰到這個比較好,花了點時間調試出來了,請看:

 

        這款外掛程式叫jqueryMagicTabs,實現了準系統,如添加選項卡,選擇指定的選項卡。當添加的選項卡超過一定長度時會出現左右滑動的按鈕,同時支援滑鼠滑動選項卡。

       這段代碼如下所示:

[html]
<%@ page language="java"contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type"content="text/html; charset=UTF-8"> 
<title>MagicTabs的基礎用法</title> 
<link href="./css/default.css"type="text/css" rel="stylesheet"> 
<link href="./css/tabs.css"type="text/css" rel="stylesheet"> 
<script type="text/javascript"src="./js/jquery.js"></script> 
<script type="text/javascript"src="./js/cn.js"></script> 
<script type="text/javascript"src="./js/core.js"></script> 
<script type="text/javascript"src="./js/ui.js"></script> 
<script type="text/javascript"src="./js/global.js"></script> 
<script type="text/javascript"src="./js/mousewheel.js"></script> 
<script type="text/javascript"src="./js/tab/tabs.js"></script> 
<script type="text/javascript"src="./js/ga.js"></script> 
<script type="text/javascript"> 
$(function(){ 
    var dd = [], i=0; 
    for(i=0; i<10; i++){ 
       var a = { 
           code: 'tab' + i, 
           title: '選項卡  ' + i, 
           closeable: i>0, 
           el: '選項卡 ' + i // You can put anything here 
       }; 
       dd.push(a); 
    } 
    var tabs = $('.tabs'); 
    tabs.mac('tabs', { 
       tabWidth: 80, //Use fix width 
       items: dd, 
       onCloseTab: function(me, c, a){ 
           tnCbx.find('[value=' + c + ']').remove(); 
           return true; 
       } 
    }).selectFirst(); 
    var thd = tabs.children('.head'), thm = thd.children('.main'); 
    thd.mousewheel(function(e, delta, deltaX, deltaY){ 
       thm.scrollLeft(thm.scrollLeft() - deltaY * 40); 
       return false; 
    }); 
    //切換選擇的選項卡 
    var tnCbx = $('#tabNoCbx').change(function(){ 
       tabs.select($(this).val()); 
    }); 
    App.options(tnCbx, { 
       data: dd, 
       keyField: 'code', 
       render: function(r){ 
           return  r.title; 
       } 
    }); 
    //添加選項卡 
    var atBtn = $('#addTabBtn').click(function(){ 
       var a = tabs.addTab({ 
           code: 'tab' + i, 
           title: '選項卡  ' + i, 
           closeable: i>0, 
           el: '選項卡 ' + i // You can put anything here 
       }); 
       tabs.select('tab' + i); 
       tnCbx.append('<optionvalueoptionvalue="tab' 
           + i + '">選項卡 ' + i + '</option>'); 
       i++; 
    }); 
}); 
</script> 
<style type="text/css"> 
    #demo{ 
       position:absolute; 
       width: 600px; 
       height: 400px; 
       top: 50px; 
       left: 200px; 
    } 
</style> 
</head> 
<body> 
    <div id="demo"> 
       <div class="toolbar"> 
           <div class="item "id="txt">請選擇:</div> 
           <div class="item"><select id="tabNoCbx" style="margin: 2px;"></select></div> 
           <div class="sqrt"></div> 
           <div class="itembutton" id="addTabBtn">添加選項卡</div> 
       </div> 
       <div class="clear"></div> 
       <div class="tabs"style="height: 380px; margin: 4px;"></div> 
    </div> 
</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.