JQuery UI Tabs, Change tab URL (JQuery 1.10+)

久未见 提交于 2019-12-12 02:33:01

问题


Is there a way to modify the link to a tab in jquery ui through jquery/javascript?

Sample problem is like

A tab have URL "http://thanksforyourhelp/greatly/appreciated/"

If a form is submitted on that tab, data is written to the database. The response gives an ID of the row added to the database.

Next time that specific tab is visited the link should actually be

'http://thanksforyourhelp/greatly/appreciated/ID' 

where the ID is now known since the response from the form (ajax here as well) sent it back. When this response came I've to reload the current tab with the URL having ID in it.

Prior to JQuery 1.10. We can do something like this

$("#tabs").tabs("url", index, url);

how we can do this in JQuery UI 1.10+. As URL method is removed in JQuery 1.10?


回答1:


Do something like this in the complete of form submit. This will change the URL of currently active tab and reloads the tab.

var tabs = $("#tabs");
var currentTabIndex = tabs.tabs("option", "active");
var tab = $(tabs.data('uiTabs').tabs[currentTabIndex]);
tab.find('.ui-tabs-anchor').attr('href', "http://thanksforyourhelp/greatly/appreciated/ID");
// If cached initially. Remove cache then
tab.data( "loaded", false);
tabs.tabs("load", currentTabIndex);



回答2:


The tab definition triggered errors for me; Had to rewrite it like this:

var tab = $(tabs.data()['ui-tabs'].tabs[currentTabIndex]);


来源:https://stackoverflow.com/questions/17961644/jquery-ui-tabs-change-tab-url-jquery-1-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!