我正在使用以下代码在单击时更改选项卡颜色
$("ul.tabs").tabs("> .pane");
但它正在抛出错误
uncaught exception: cannot call methods on tabs prior to initialization; attempted to call method '> .pane'
有人可以帮我解决这个错误吗?
我正在使用以下代码在单击时更改选项卡颜色
$("ul.tabs").tabs("> .pane");
但它正在抛出错误
uncaught exception: cannot call methods on tabs prior to initialization; attempted to call method '> .pane'
有人可以帮我解决这个错误吗?
正如例外所说,它非常简单。您的选项卡必须先初始化,然后才能处理它们。所以初始化它们。
function(){
$("ul.tabs").tabs();
}
或简单地使用
$("ul.tabs").tabs().tabs($("div.panes > div"), action);
我不知道您希望使用此代码得到什么,但这是错误的。您不应该将选择器作为.tabs()
方法的属性传递。查看jQuery UI Tabs API了解如何使用它。
您的初始化无效。参数部分试图调用 tabs 命名空间中的方法,该("> .pane")
方法肯定不存在。
您还可以在包含列表 (ul) 的 div 上初始化 tabs 方法,而不是 ul 本身。
假设 html 结构:
<div id="tabs">
<ul>
// the list items
</ul>
// tab content divs (all with class="pane")
</div>
像这样的东西:
$('#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');
});
在jqueryui.com/tabs上阅读更多信息