製作 tab 的小型 jQuery 程式碼

編寫、設計網頁與程式。

版主: hamu278, 銘仔

版面規則
  • 本版面亦可以討論網頁寄存公司

製作 tab 的小型 jQuery 程式碼

文章bananasims » 2009-03-16, 00:11

目錄 HTML
代碼: 選擇全部
<ul id="list_menu">
<li><a href="#list_aaa">AAA</a></li>
<li><a href="#list_bbb">BBB</a></li>
<li><a href="#list_ccc">CCC</a></li>
</ul>


內容 HTML
代碼: 選擇全部
<div id="list_aaa">
AAA 的內容
</div>

<div id="list_bbb">
BBB 的內容
</div>

<div id="list_ccc">
CCC 的內容
</div>


程式碼
代碼: 選擇全部
// hide all elements
var objs = $('#list_menu a').each(function() {
   jQuery(jQuery(this).attr('href')).hide();
});

// click the menu to hide the elements
var last_id = '#list_aaa'; // please fill in the id of the first element yourself
$('#list_menu a').click(function() {
   var id = jQuery(this).attr('href');
   $(last_id).hide();
   $(id).show();
   last_id = id;
});
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: 製作 tab 的小型 jQuery 程式碼

文章SkyBread » 2009-04-30, 22:57

我想問呢...
如果呢到每一個tab都有一大堆野要load...
係唔係會load好耐??...
SkyBread
 

Re: 製作 tab 的小型 jQuery 程式碼

文章銘仔 » 2009-04-30, 23:07

SkyBread 寫:我想問呢...
如果呢到每一個tab都有一大堆野要load...
係唔係會load好耐??...

等同於你一頁內有幾多野一樣咁 load ... :oops:
頭像
銘仔
金星會員
 
文章: 3017
註冊時間: 2007-04-05, 20:36

Re: 製作 tab 的小型 jQuery 程式碼

文章SkyBread » 2009-05-10, 00:58

thx銘仔...

to bnn
個source code好似唔work...

呢個係改自你果個的...
代碼: 選擇全部
$(function () {
   // hide all elements
   var objs = $('#list_menu a').each(function() {
      jQuery(jQuery(this).attr('href')).hide();
   });

   // click the menu to hide the elements
   var last_id = '#list_aaa'; // please fill in the id of the first element yourself
   $(last_id).show();
   $('#list_menu a').click(function() {
      var id = jQuery(this).attr('href');
      $(last_id).hide();
      $(id).show();
      last_id = id;
   });
});
最後由 SkyBread 於 2009-05-10, 01:02 編輯,總共編輯了 1 次。
SkyBread
 

Re: 製作 tab 的小型 jQuery 程式碼

文章bananasims » 2009-05-10, 00:59

點解要加,我用都無事 :oops:
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: 製作 tab 的小型 jQuery 程式碼

文章SkyBread » 2009-05-10, 01:02

bananasims 寫:點解要加,我用都無事 :oops:

唔知 :oops:
不過我加左先冇事...
唔加就有事...
SkyBread
 


回到 [B1] 網頁製作、程式編寫與介面設計



誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 12 位訪客

cron