检查jQuery UI选项卡是否已初始化(不检查类) [英] check if jQuery UI tabs have been initialized (without checking for class)

查看:116
本文介绍了检查jQuery UI选项卡是否已初始化(不检查类)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery UI选项卡-我编写了一个与ui选项卡集成的插件. 如果没有调用.tabs(),我已经有了插件设置来启动jQuery UI选项卡,但这只是进行了简单的类检查:

Using jQuery UI tabs - and I've written a plugin that integrates with ui tabs. I've got the plugin setup to initiate jQuery UI tabs if it .tabs() hasn't been called, but this just does a simple class check:

 if(!$globalTabs.hasClass("ui-tabs")){
    $globalTabs.tabs();
 }

但这是有问题的,因为开发人员通常为了避免FOUC,将UI类添加到选项卡中,以便在document.ready之前获得更好的初始呈现.

But this is problematic, because often to avoid FOUC, developers add in the UI classes to the the tabs to get a better initial render before document.ready.

我可以检查另一个类,例如`ui-widget1,但是想知道是否还有另一种/更好的方法?

I could check for a different class, such as `ui-widget1, but wondering if there's another/better way?

推荐答案

您可以使用 data()查询附加的小部件:

You can query the attached widget with data():

if (!$globalTabs.data("tabs")) {
    $globalTabs.tabs();
}

此行为记录在jQuery UI的

This behavior is documented in the Widget factory page of jQuery UI's Development & Planning Wiki:

  • 可通过$( "#something" ).data( "pluginname" )

  • Plugin instance accessible via $( "#something" ).data( "pluginname" )

  • 对包含DOM元素的jQuery对象的引用是 作为this.element实例的属性可用,因此它是 易于在对象和元素之间来回移动.
  • A reference to a jQuery object containing the DOM element is available as a property of the instance as this.element, so it is easy to go back and forth between the object and the element.

更新:从jQuery UI 1.9起,窗口小部件键成为窗口小部件的全限定名称,点用短划线代替,如下所示:

Update: From jQuery UI 1.9 onwards, the widget key becomes the widget's fully qualified name, with dots replaced with dashes, as in:

if (!$globalTabs.data("ui-tabs")) {
    $globalTabs.tabs();
}

在1.9中仍支持使用非限定名称,但已弃用,并且在1.10中将不再支持.

Using unqualified names is still supported in 1.9 but is deprecated, and support will be dropped in 1.10.

这篇关于检查jQuery UI选项卡是否已初始化(不检查类)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆