我在页面右侧设置了一些jQuery选项卡,但在Safari中,最后一个选项卡链接是重复的,即“静态页面”显示两次。这在其他浏览器中不会发生。任何帮助,为什么会发生这种情况。
http://ghostpool.com/wordpress/reviewit/review/quisque-ultricies-consequat/
这是我的标签代码:
jQuery(document).ready(function(){
// We can use this object to reference the panels container
var panelContainer = jQuery('div#panels');
// Find panel names and create nav
// -- Loop through each panel
panelContainer.find('div.panel').each(function(n){
// For each panel, create a tab
jQuery('div#tabs-box ul').append('<li class="tab"><a href="#' + (n+1) + '">' + jQuery(this).attr('title') + '</a></li>');
});
// Determine which tab should show first based on the URL hash
var panelLocation = location.hash.slice(1);
if(panelLocation == '1'){
var panelNum = panelLocation;
} else if(panelLocation == '2'){
var panelNum = panelLocation;
} else if(panelLocation == '3'){
var panelNum = panelLocation;
} else if(panelLocation == '4'){
var panelNum = panelLocation;
} else if(panelLocation == '5'){
var panelNum = panelLocation;
} else if(panelLocation == '6'){
var panelNum = panelLocation;
} else if(panelLocation == '7'){
var panelNum = panelLocation;
} else if(panelLocation == '8'){
var panelNum = panelLocation;
} else if(panelLocation == '9'){
var panelNum = panelLocation;
} else if(panelLocation == '10'){
var panelNum = panelLocation;
}else{
var panelNum = '1';
}
// Hide all panels
panelContainer.find('div.panel').hide();
// Display the initial panel
panelContainer.find('div.panel:nth-child(' + panelNum + ')').fadeIn('slow');
// Change the class of the current tab
jQuery('div#tabs-box ul').find('li.tab:nth-child(' + panelNum + ')').removeClass().addClass('tab-active');
// What happens when a tab is clicked
// -- Loop through each tab
jQuery('div#tabs-box ul').find('li').each(function(n){
// For each tab, add a 'click' action
jQuery(this).click(function(){
// Hide all panels
panelContainer.find('div.panel').hide();
// Find the required panel and display it
panelContainer.find('div.panel:nth-child(' + (n+1) + ')').fadeIn('slow');
// Give all tabs the 'tab' class
jQuery(this).parent().find('li').removeClass().addClass('tab');
// Give the clicked tab the 'tab-active' class
jQuery(this).removeClass().addClass('tab-active');
});
});
});
答案 0 :(得分:0)
由于某种原因,find方法返回一个额外的元素,很难说明基于所有HTML的原因。您页面的精简示例适用于Safari
要修复脚本,如果只搜索带有类面板的元素(而不是div.panel
),它应该可以在Safari中使用
panelContainer.find('.panel').each(function(n){