最后一个 jQuery 选项卡元素在 Safari 中重复
我在页面右侧设置了一些 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');
});
});
});
I have some jQuery tabs set up on the right of the page, however in Safari the last tab link is duplicated i.e. "Static Page" is shown twice. This does not occur in other browsers. Any help as to why this happening.
http://ghostpool.com/wordpress/reviewit/review/quisque-ultricies-consequat/
This is my tab code:
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');
});
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于某种原因,find 方法返回了一个额外的元素,很难根据所有 HTML 来判断原因。页面的精简示例可在 Safari 中运行
要修复您的脚本,如果您仅搜索带有类面板的元素(而不是
div.panel
),它应该可以在 Safari 中运行The find method is returning an extra element for some reason, hard to tell why based on all the HTML. A stripped down example of your page works in Safari
To fix your script, if you search for just the elements with the class panel (instead of
div.panel
), it should work in Safari