【问题标题】:uncaught exception: cannot call methods on tabs prior to initialization未捕获的异常:无法在初始化之前调用选项卡上的方法
【发布时间】:2020-06-02 17:17:31
【问题描述】:

我正在使用以下代码更改点击时的标签颜色

  $("ul.tabs").tabs("> .pane");

但它正在抛出错误

uncaught exception: cannot call methods on tabs prior to initialization; attempted to call method '> .pane'

有人可以帮我解决这个错误吗?

【问题讨论】:

  • 为什么你认为它会帮助你设置颜色?
  • 你使用的是什么标签系统(插件)?

标签: javascript jquery


【解决方案1】:

正如例外所说,它非常简单。您的选项卡必须先初始化,然后才能处理它们。所以初始化它们。

function(){
$("ul.tabs").tabs();
}

或者简单地使用

$("ul.tabs").tabs().tabs($("div.panes > div"), action);

【讨论】:

    【解决方案2】:

    我不知道您希望使用此代码得到什么,但这是错误的。 您不应将选择器作为 .tabs() 方法的属性传递。 使用方法请看jQuery UI Tabs API

    【讨论】:

      【解决方案3】:

      您的初始化无效。 ("> .pane") 参数部分正在尝试调用 tabs 命名空间中的方法,该方法肯定不存在。

      您还可以在包含列表 (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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多