1 頁 (共 1 頁)

製作 tab 的小型 jQuery 程式碼

文章發表於 : 2009-03-16, 00:11
bananasims
目錄 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;
});

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

文章發表於 : 2009-04-30, 22:57
SkyBread
我想問呢...
如果呢到每一個tab都有一大堆野要load...
係唔係會load好耐??...

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

文章發表於 : 2009-04-30, 23:07
銘仔
SkyBread 寫:我想問呢...
如果呢到每一個tab都有一大堆野要load...
係唔係會load好耐??...

等同於你一頁內有幾多野一樣咁 load ... :oops:

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

文章發表於 : 2009-05-10, 00:58
SkyBread
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;
   });
});

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

文章發表於 : 2009-05-10, 00:59
bananasims
點解要加,我用都無事 :oops:

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

文章發表於 : 2009-05-10, 01:02
SkyBread
bananasims 寫:點解要加,我用都無事 :oops:

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