我有這樣的HTML結構:jQuery的切換/顯示隱藏的div
<div id="home">
<div class="section_header">
<h1 class="left" data-target="newest"><?=lang('home_newest');?></h1>
...
</div>
<div id="newest">
...
</div>
<div class="section_header">
<h1 class="left" data-target="best"><?=lang('home_newest');?></h1>
...
</div>
<div id="best">
...
</div>
</div>
我所試圖做的是一個切換/顯示&隱藏的函數,在點擊工作.section_header> H1,以示與DIV在h1標籤內的數據目標中定義的id並隱藏其他標籤,但始終打開一個標籤並在頁面加載時默認打開#newest。
我曾嘗試:
$('.section_header h1').click(function(){
var selected = $(this).data('target');
//$('#'+selected).hide().filter('#'+selected).show();
$('#home > #'+selected).hide();
}).first().click();
的註釋行不工作,但.hide只有它。
我發現這一點:http://www.learningjquery.com/2007/02/more-showing-more-hiding並認爲它可以工作,但我沒有成功,告訴它關閉其格,並顯示
編輯: 有一兩件事,怎麼能做到這一點當點擊可見的div關閉它並打開下一個?
請閱讀的編輯我的後 – Alex 2012-01-16 00:46:20
任何更新方式? – Alex 2012-01-17 11:45:33
更新!一些改進,它適合您的需求,我希望;)http://jsbin.com/unetay/6/edit 檢查我的意見,特別是對於循環參數或只問我你的問題。 – Way 2012-01-17 13:20:57