Javascript jQuery 错误 - 无法在初始化之前调用选项卡上的方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13557764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 12:21:49  来源:igfitidea点击:

jQuery error - Cannot call methods on tabs prior to initialization

javascriptjquery

提问by ssk

I updated to the latest version of jQuery and I see this error.

我更新到最新版本的 jQuery,我看到了这个错误。

Error:

错误:

Uncaught Error: cannot call methods on tabs prior to initialization; attempted to call method 'div.panes > div'

未捕获的错误:无法在初始化之前调用选项卡上的方法;试图调用方法“ div.panes > div

Complete Snippet:

完整片段:

html:

html:

<div id="nav"> <!-- Start Page Navigation -->
    <ul class="tabs page">
        <li><a href="#tab1">Tab1</a></li>
        <li><a href="#tab2">Tab2</a></li>
        <li><a href="#tab3">Tab3</a></li>
        <li><a href="#tab4">Tab4</a></li>
    </ul>
    <div class="clear"></div>
</div> <!-- End Page Navigation -->

JS:

JS:

$(document).ready(function() {
    $("div.header div.version").css({ '-moz-border-radius': '6px', '-webkit-border-radius': '6px' });
    $("div#contact_form .text_input").css({ '-moz-border-radius': '4px', '-webkit-border-radius': '4px' });
    $("div#about div.right").css({ '-moz-border-radius' : '8px', '-webkit-border-radius': '8px' });
    $("div#contact_form p label").css({ 
            '-moz-border-radius-topleft': '4px', 
            '-moz-border-radius-bottomleft': '4px', 
            '-webkit-border-bottom-left-radius' : '4px',
            '-webkit-border-top-left-radius' : '4px'  
    });
    $("select").css({ '-khtml-appearance' : 'none' });
    $('#reviews').serialScroll({
      items: 'div',
      axis: 'y',
      duration: 800,
      interval: 5000,
      cycle: true
    });
    $('#reviews').trigger('next');
    $("a.screenshots").fancybox({
            'transitionIn'  :   'elastic',
            'transitionOut' :   'elastic',
            'speedIn'       :   400, 
            'speedOut'      :   400, 
            'overlayShow'   :   false
        });
        $('input#send').click(function() {
        var name = $('input#name').val();
        var email = $('input#email').val();
                var topic = $('select#topic option:selected').val();
        var message = $('textarea#message').val();
        $.ajax({
            type: 'post',
            url: 'scripts/send_email.php',
            data: 'name=' + name + '&email=' + email + '&topic=' + topic + '&message=' + message,

            success: function(results) {
                $('p.validation').html(results);
            }
        }); // end ajax
    });
 $("#ul.tabs").tabs("div.panes > div", { history: true });
});

I don't see the error if I use:

如果我使用,我看不到错误:

 $("#content ul.tabs").tabs("div.panes > div", { history: true });

enter image description here

在此处输入图片说明

回答by rajesh kakawat

try this

尝试这个

  $("ul.tabs").tabs("div.panes > div", { history: true });

instead of this

而不是这个

 $("#ul.tabs").tabs("div.panes > div", { history: true });

回答by ssk

Following fixed my problem:

以下解决了我的问题:

$("ul.tabs").tabs($("div.panes > div"), { history: true });