jQueryUI - 动态添加具有相同目标的选项卡
我正在使用 jQueryUI 插件,并且我希望有几个引用同一 div 的选项卡(其内容根据所选选项卡是动态的)。
当选项卡是静态的时,它可以工作,例如:
<div id="tabs">
<ul id="tab-links-container">
<li class="tab-link">
<a href="#main-tab">One</a>
</li>
<li class="tab-link">
<a href="#main-tab">Two</a>
</li>
<li class="tab-link">
<a href="#main-tab">Three</a>
</li>
</ul>
<div class="tab-body" id="main-tab">
<span>Here is the shared tabs content</span>
</div>
但是当我尝试动态添加选项卡时,我遇到了一些非常奇怪的行为。我是这样做的:
$("#tabs").tabs("add", "#main-tab", tabTitle);
奇怪的行为如下:
- 第一个选项卡似乎被选中,但我没有看到任何内容(目标 div 为空白)。
- 单击第二个选项卡时,它被选中,显示内容,但第一个选项卡仍然显示为选中状态,并且不可“单击”。
- 只有当选择第三个选项卡时,整个机制才会恢复正常,一切都会恢复正常。
当尝试玩类似的场景时,我遇到了其他错误,例如选项卡(目标)的内容被隐藏,甚至选项卡本身突然被删除。
这适用于 IE7/8 和 Chrome。
还有其他人也遇到过类似的问题吗?这是一个已知的错误还是我在这里遗漏了一些东西?
谢谢,
I'm using jQueryUI plugin, and I wish to have several tabs that refer to the same div (which its content is dynamic according to the selected tab).
It works, when i the tabs are static, for example:
<div id="tabs">
<ul id="tab-links-container">
<li class="tab-link">
<a href="#main-tab">One</a>
</li>
<li class="tab-link">
<a href="#main-tab">Two</a>
</li>
<li class="tab-link">
<a href="#main-tab">Three</a>
</li>
</ul>
<div class="tab-body" id="main-tab">
<span>Here is the shared tabs content</span>
</div>
But when I try to dynamically add a tab, i experience some really bizarre behaviors. Here's how i did it:
$("#tabs").tabs("add", "#main-tab", tabTitle);
The weird behavior is as follows:
- The first tab appears to be selected, but i see no content (the target div is blank).
- When clicking on the second tab, it's selected, the content is shown, but the first tab still appears as selected too, and is not "clickable".
- Only when selecting the third tab, the whole mechanism sorts out, and everything goes back to normal.
When trying to play with similar scenarios i encountered with other bugs, such as the content of the tab (the target) is hidden, or even the tab itself is suddenly erased.
This goes to IE7/8 and Chrome.
Has anyone else also encountered similar problems? Is it a known bug or am I missing something here?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论