我的网页上有标签。根据我单击的选项卡,我根据选项卡加载数据。这是我的剧本。每个选项卡都有很多要显示的数据。当我单击选项卡时,它会显示有关应用程序集的数据,另一个选项卡显示有关不同应用程序的信息等等。我有大约30个标签。我想要做的是,当我单击一个选项卡时,我希望该选项卡处于活动状态,我的整个页面应该只包含该选项卡和该选项卡的数据。如果未单击选项卡,则不应在页面上显示有关未单击选项卡的数据。包含未单击选项卡数据的div应为空。这是我的剧本。任何想法如何清空属于未被删除的标签的div?
<script>
// Wait until the DOM has loaded before querying the document
$(document).ready(function(){
$('ul.tabs').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('a');
// 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 = $($links.filter('[href="'+location.hash+'"]')[0] || $links[0]);
$active.addClass('active');
$content = $($active.attr('href'));
// Hide the remaining content
$links.not($active).each(function () {
$($(this).attr('href')).hide();
});
// Bind the click event handler
$(this).on('click', 'a', function(e){
// Make the old tab inactive.
$active.removeClass('active');
$content.hide();
// Update the variables with the new link and content
$active = $(this);
$content = $($(this).attr('href'));
// Make the tab active.
$active.addClass('active');
$content.show();
// Prevent the anchor's default click action
e.preventDefault();
});
});
});
</script>
答案 0 :(得分:0)
请参阅以下代码:
// Make the old tab inactive.
$active.removeClass('active');
$content.html(''); // <----- add this line
$content.hide();