如何在 Jquery UI Tabs 中获取选定的选项卡面板元素?
问题。我有多个选项卡,它们的内容是通过ajax加载的,因此选项卡面板的div id是动态分配的。我有一个表单,由 这个 jquery 插件 通过绑定到 tabs.load 事件的回调函数进行 ajaxified我向它传递了一个参数 ui.panel,以便 ajaxForm() 知道加载结果的目标:
function initAjaxForms(loadtab)
{
$('form').ajaxForm({target:loadtab, success:initAjaxForms});
}
这工作正常,除非当我提交表单并且 PHP 将其返回为无效时,我无法再 ajaxify 它(的当然,该函数是在没有 loadtab 参数的情况下调用的)。完美的解决方案是为选项卡提供更多选项,以便我可以执行以下操作:
function initAjaxForms()
{
var selected = $('tabs').tabs('option', 'selectedpanel');
$('form').ajaxForm({target:selectedpanel, success:initAjaxForms});
}
但这显然不是它。有什么想法吗?
The problem. I have multiple tab, their content is loaded via ajax, so the div id's of tabs' panels are assigned dynamically. I have a form in one, ajaxified by this jquery plugin by a callback function bound to tabs.load event I pass it one parameter, the ui.panel, so that the ajaxForm() knows the target where to load result:
function initAjaxForms(loadtab)
{
$('form').ajaxForm({target:loadtab, success:initAjaxForms});
}
This works fine, EXCEPT when I submit the form and PHP returns it as not valid, I cannot ajaxify it anymore (of course, the function is called with no loadtab parameter). the perfect solution would be to have more options to tabs so that i can do something like this:
function initAjaxForms()
{
var selected = $('tabs').tabs('option', 'selectedpanel');
$('form').ajaxForm({target:selectedpanel, success:initAjaxForms});
}
but this is obviously not it. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
选择未使用 .ui-tabs-hide 隐藏的 .ui-tabs-panel:
Select the .ui-tabs-panel that isn't hidden with .ui-tabs-hide:
也许 jqueryUI 已经改变,接受的答案对我不起作用。这是有效的:
Maybe jqueryUI has changed, the accepted answer does not work for me. Here is what works:
我最终通过一点技巧解决了这个问题,但我觉得这不是一个完美的解决方案:
有人有更好的主意吗?
I eventually figured it out with a little hack, but I sense this is not a perfect solution:
anyone with better idea?
我一直遇到这个问题,虽然这是一个老问题,但正是这个问题让我找到了这个答案,该答案有效:
I've been having this very problem, and whilst this is an old question, it's the one that led me to this answer, which works:
这将为您提供所选选项卡窗格的对象。
This one will get you the object of the selected tab pane.
这是更简单的版本:
Here is more simpler version:
从 http://api.jqueryui.com/tabs/#option-active 您可以这样做:
From http://api.jqueryui.com/tabs/#option-active you can do this: