我有以下 html,我想使用 jquery 制作简单的标签
<td style="border-color: black; border-style: solid; border-width: 1px 0 1px 1px;">
<div id="cont-1-1">
My first tab content
</div>
<div id="cont-2-1">
My second tab content
</div>
</td>
<td style="width: 30px">
<div id="tab-box">
<div style="height: 121px;"><img class="cont-1-1" src="/Images/Tab1.png" /></div>
<div style="border-left: 1px solid Black;"><img class="cont-2-1" src="/Images/Tab2.png" /></div>
<div style="border-left: 1px solid Black; height: 40px;"></div>
</div>
</td>
</td>
我的选项卡标题在哪里Tab1.Png
以及是选项卡内容,我不想为此使用任何 jquery 插件,只需要在单击选项卡时进行一些简单的操作,隐藏和显示内容Tab2.Png
div id :cont-1-1 and 2-1
这就是我正在尝试的:
$(document).ready(function () {
$('#tab-box').each(function () {
// For each set of tabs, we want to keep track of
// which tab is active and it's associated content
var $active, $content, $links = $(this).find('img');
// If the location.hash matches one of the links, use that as the active tab.
// If no match is found, use the first link as the initial active tab.
$active = $(Find First Tab from div);
$active.addClass('active');
$content = $($active.attr('class'));
// Hide the remaining content
$links.not($active).each(function () {
$($(this).attr('href')).hide();
});
谢谢