更改jQuery UI选项卡的Selected选项卡 [英] Change Selected tab of jQuery UI tabs
问题描述
这个问题已经被问过几次了,但是没有一个与我的情况相似.
The question has been asked a few times before, but none of them are similar to my scenario.
我有jQuery Tabs控件,可通过ajax加载我的标签页:
I have jQuery Tabs control that loads my tabs via ajax:
<div id="tabs">
<ul>
<% if (AccessControll.HasAccess(Url.Action("ViewSchemeInformation","Scheme"))){%>
<li><a id="tab_1" href="<%= Url.Action("ViewSchemeInformation","Scheme", new {schemeNumber = Model.SchemeNumber}) %>">Information</a></li>
<%}%>
<% if (AccessControll.HasAccess(Url.Action("SchemeUpdate", "Scheme"))){%>
<li><a id="tab_2" href="<%= Url.Action("SchemeUpdate","Scheme", new {schemeNumber = Model.SchemeNumber}) %>">Update</a></li>
<%}%>
<%if (AccessControll.HasAccess(Url.Action("MinimumRequirements","Scheme"))){%>
<li><a id="tab_3" href="<%= Url.Action("MinimumRequirements","Scheme", new {schemeNumber = Model.SchemeNumber}) %>">Minimum Requirements</a></li>
<%}%>
</ul>
这些标签页是根据访问权限显示的,因此我的标签页索引永远不会相同,因此我在每个href
上都添加了id
.
These tabs are shown based on access, so my tab index's are never the same, hence I have added an id
to each href
.
我从各个地方链接到该特定页面,每个链接都必须转到该页面并选择它所引用的选项卡.
I link to this specific page from various places and each link must go to this page and select the tab it refers to.
我的网址看起来像这样:http://localhost:34412/Scheme/ViewSchemeDetails/BS-000469800000?activeTab=1
My url will look something like this: http://localhost:34412/Scheme/ViewSchemeDetails/BS-000469800000?activeTab=1
如何基于查询字符串中的activeTab参数使用jQuery选择选项卡?
How can I select the tab using jQuery based on the activeTab parameter in my querystring?
请注意,查询字符串中的数字始终与我的href
的ID相对应.
Note that number in the querystring always corresponds to the id of my href
.
推荐答案
获取查询字符串:
var queryString = window.location.search;
获取activeTab
部分:
var activeTab = queryString.match(/\bactiveTab=([^&]*)/)[1];
选择具有正确ID的标签:
Select the tab with the right ID:
$('#tab_' + activeTab).click();
这篇关于更改jQuery UI选项卡的Selected选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!