使用 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();
}
此行为记录在 Widget factory 中jQuery UI 的页面 Development & Planning Wiki :
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 中将不再支持。
关于jquery - 检查 jQuery UI 选项卡是否已初始化(不检查类),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12393773/