检查是否已初始化jQuery UI选项卡(不检查类)

使用jQuery UI选项卡 – 我编写了一个与ui标签集成的插件.
如果没有调用.tabs(),我有插件设置来启动jQuery UI选项卡,但这只是一个简单的类检查:
if(!$globalTabs.hasClass("ui-tabs")){
    $globalTabs.tabs();
 }

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

我可以检查一个不同的类,比如`ui-widget1,但想知道是否还有其他/更好的方法

解决方法

您可以使用 data()查询附加的小部件:
if (!$globalTabs.data("tabs")) {
    $globalTabs.tabs();
}

在jQuery UI的Development & Planning WikiWidget factory页面中记录了此行为:

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

    • 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开始,the widget key becomes the widget’s fully qualified name,with dots replaced with dashes,如:

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

1.9中仍然支持使用非限定名称但不推荐使用,支持将在1.10中删除.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...