javascript 未捕获的异常:无法在初始化之前调用选项卡上的方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13820319/
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
uncaught exception: cannot call methods on tabs prior to initialization
提问by NoviceToDotNet
I am using the following code to change the tab color on click
我正在使用以下代码在单击时更改选项卡颜色
$("ul.tabs").tabs("> .pane");
but it is throwing the error
但它抛出错误
uncaught exception: cannot call methods on tabs prior to initialization; attempted to call method '> .pane', could somebody help me with this what is this error?
未捕获的异常:无法在初始化之前调用选项卡上的方法;试图调用方法“> .pane”,有人能帮我解决这个错误吗?
回答by Aravind
Its pretty straight forward as the exception says. Your tabs must be initialized before you can work on them. So initialize them.
正如例外所说,它非常简单。您的选项卡必须先初始化,然后才能对其进行处理。所以初始化它们。
function(){
$("ul.tabs").tabs();
}
or simply by using
或者简单地使用
$("ul.tabs").tabs().tabs($("div.panes > div"), action);
回答by pxx
I don't know what do you expect to get using this code, but it's wrong.
You shouldn't pass selector as an attribute for .tabs()
method.
Look at the jQuery UI Tabs APIfor how to use it.
我不知道您希望使用此代码得到什么,但这是错误的。您不应该将选择器作为.tabs()
方法的属性传递。查看jQuery UI Tabs API了解如何使用它。
回答by Tapirboy
Your initialization is invalid. The ("> .pane")
argument part is trying to call a method in the tabs namespace, which certainly does not exist.
您的初始化无效。该("> .pane")
参数部分试图调用标签的命名空间,这肯定是不存在的方法。
Also you initialize tabs method on the div containing the list (ul), not the ul itself.
您还可以在包含列表 (ul) 的 div 上初始化 tabs 方法,而不是 ul 本身。
Assuming html-structure:
假设 html 结构:
<div id="tabs">
<ul>
// the list items
</ul>
// tab content divs (all with class="pane")
</div>
Something like this:
像这样的东西:
$('#tabs').tabs();
$('#tabs li').bind('click', function() {
// change bg color to 'teal' of all divs with class name '.pane' inside #tabs div
$('#tabs').find('.pane').css('background-color', 'teal');
});
Read more on jqueryui.com/tabs
在jqueryui.com/tabs上阅读更多内容