如何在 jQuery UI 选项卡中初始化选项卡式容器外部的选项卡式内容?
是否可能?如果可以,您将如何初始化选项卡容器元素之外的选项卡式内容?
该文档全部包含同一容器中的选项卡和选项卡内容,例如:
<div id="tabs">
<ul>
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<div id="tab1">
Tab 1 content
</div>
<div id="tab2">
Tab 2 content
</div>
<div id="tab3">
Tab 3 content
</div>
</div>
但是,对于我正在处理的项目,导航和选项卡内容不位于同一容器中,因此:
<nav id="tabs">
<ul>
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
</nav>
...
<article>
<section id="tab1">
Section 1 content
</section>
<section id="tab2">
Section 2 content
</section>
<section id="tab3">
Section 3 content
</section>
</article>
Is it possible and if so, how would you initialize tabbed content outside of the tabs container element?
The documentation all includes the tabs and the tab content in the same container, example:
<div id="tabs">
<ul>
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<div id="tab1">
Tab 1 content
</div>
<div id="tab2">
Tab 2 content
</div>
<div id="tab3">
Tab 3 content
</div>
</div>
However, for the project I'm working on, the navigation and the tab content are not located within the same container, thus:
<nav id="tabs">
<ul>
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
</nav>
...
<article>
<section id="tab1">
Section 1 content
</section>
<section id="tab2">
Section 2 content
</section>
<section id="tab3">
Section 3 content
</section>
</article>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看
tabs< 的源代码/code>
(行 228 和 233),似乎不可能这样做不需要某种“黑客”,比如像 William Niu 建议的那样克隆导航,或者包含两者
tabs
的当前迭代会查找父元素内的选项卡面板;即它使用find()
。但我仍然希望您可以使用通用容器,看起来您可以将导航(和面板)放置在容器内的任何位置(L215),并且您不必将容器放置在导航或面板旁边或附近,例如,实际的选项卡元素可以位于容器的深处。
更新:现在有一个官方方法可以做到这一点:http://bugs. jqueryui.com/ticket/7715
Looking at the source code of
tabs
(Lines 228 and 233), it seems impossible to do this without some sort of "hack" like cloning the navigation as William Niu suggests, or containing both the navigation and the panels inside a common container, etc. The current iteration oftabs
looks for the tab panels inside the parent element; i.e. it usesfind()
.But I'm still hopeful that you can use a common container, it looks like you can place the navigation (and panels) anywhere inside the container (L215), and you don't have to place the container next to or near the navigation or panels, e.g. the actual tab elements can be deep within the container.
Update: Now there is an official way to do this: http://bugs.jqueryui.com/ticket/7715
我不知道这是否适合您,但一种解决方案是访问包含两者的元素。
例如
看看这个 fiddle
I don't know if this would work for you, but one solution would be to access an element that does contain both.
for example
Check out this fiddle
如果您只是希望它对用户具有这种外观,您可以将导航栏克隆到其他位置并删除原始导航栏。
查看实际操作:http://jsfiddle.net/william/QAJ2Z/1/。
If you just want it to have that look to the user, you could clone the navigation bar to somewhere else and remove the original one.
See this in action: http://jsfiddle.net/william/QAJ2Z/1/.