我正在使用 jQuery 将内容排列到多个选项卡中。目前,它非常适合其预期目的,即在单击选项卡时显示特定<div>
内容。我如何能够创建一个可以切换“显示所有选项卡内容”的按钮?假设按钮看起来像这样:<div class="toggle"></div>
当前代码:
/* jQuery */
$('#hb_container div').click(function(){
var tab_id = $(this).attr('data-tab');
$('#hb_container div').removeClass('current');
$('.tab-content').removeClass('current');
$(this).addClass('current');
$("#"+tab_id).addClass('current');
});
/* Tabs */
<div id="hb_container">
<div class="tab-link current" data-tab="tab-1"><div class="tab-link-inner">Job<br>Info</div></div>
<div class="tab-link" data-tab="tab-2"><div class="tab-link-inner">Asb.<br>By</div></div>
<div class="tab-link" data-tab="tab-3"><div class="tab-link-inner">Apl.<br>No.</div></div>
<div class="tab-link" data-tab="tab-4"><div class="tab-link-inner">Struc.<br>Eng.</div></div>
</div>
/* Tabbed content */
<div id="tab-1" class="tab-content" style="margin-top: 24px">
<div class="tab-content-title">Attachment Upload</div>
<div class="single_col_container">
<div id="frm_field_[id]_container" class="frm_form_field form-field [required_class][error_class]">
[input]
</div>
</div>
</div>
/* CSS */
#hb_container {
margin: 8px 0 8px 8px;
width: 984px;
height: 54px;
}
.tab-content {
display: none;
}
.tab-content.current {
display: inherit;
}
.tab-link {
background: #222;
color: #ddd;
cursor: pointer;
float: left;
font-family: Roboto;
font-size: 12px;
font-weight: bold;
letter-spacing: 1px;
line-height: 14px;
margin: 0 8px 0 0;
width: 54px !important;
height: 54px;
}
.tab-link:hover {
background: #181818;
color: #ffcc00;
}
.tab-link-inner {
margin-top: 11px;
}