最后一个 jQuery 选项卡元素在 Safari 中重复

发布于 2024-10-18 04:09:32 字数 2887 浏览 1 评论 0原文

我在页面右侧设置了一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

注定孤独终老 2024-10-25 04:09:32

由于某种原因,find 方法返回了一个额外的元素,很难根据所有 HTML 来判断原因。页面的精简示例可在 Safari 中运行

要修复您的脚本,如果您仅搜索带有类面板的元素(而不是 div.panel),它应该可以在 Safari 中运行

panelContainer.find('.panel').each(function(n){

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

panelContainer.find('.panel').each(function(n){
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文